gpt4 book ai didi

wcf - 使用 SSL 在 VS2015 中调试 WCF

转载 作者:太空宇宙 更新时间:2023-11-03 14:35:26 25 4
gpt4 key购买 nike

我最近被要求更改使用 ssl 的 wcf 服务。创建该项目的开发人员不再为我们工作。我遇到的问题是,当我在 visual studio 2015 中运行它时,我在标题为的对话框中弹出错误:

"Failed to add service. Service metadata may not be accessible. Make sure your service is running and exposing metadata"

错误详细信息是:

Error: Cannot obtain Metadata from https://localhost:50257/AssignmentImport.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: https://localhost:50257/AssignmentImport.svc Metadata contains a reference that cannot be resolved: 'https://localhost:50257/AssignmentImport.svc'. An error occurred while making the HTTP request to https://localhost:50257/AssignmentImport.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. The underlying connection was closed: An unexpected error occurred on a send. The handshake failed due to an unexpected packet format.HTTP GET Error URI: https://localhost:50257/AssignmentImport.svc There was an error downloading 'https://localhost:50257/AssignmentImport.svc'. The underlying connection was closed: An unexpected error occurred on a send. The handshake failed due to an unexpected packet format.

在 web.config 文件中,服务模型是:

  <system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="NetiveApi.IisHost.TimesheetImport" behaviorConfiguration="metadatadiscov">
<endpoint name="TimesheetWs" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding" contract="NetiveApi.IisHost.ITimesheetImport"/>
<endpoint name="mexHttpsBinding" binding="mexHttpsBinding" address="mex" contract="IMetadataExchange"/>
</service>
<service name="NetiveApi.IisHost.AssignmentImport" behaviorConfiguration="metadatadiscov">
<endpoint name="AssignmentWs" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding" contract="NetiveApi.IisHost.IAssignmentImport"/>
<endpoint name="mexHttpsBinding" binding="mexHttpsBinding" address="mex" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadatadiscov">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<!-- Use your own port numbers -->
<!--<add scheme="http" port="8080" />-->
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WsHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>

任务服务契约(Contract)

    [ServiceContract]
public interface IAssignmentImport
{
[OperationContract]
Acknowledgement ImportAssignment(string xml, string system, Guid authenticationToken);
}

时间表服务契约(Contract)

    [ServiceContract]
public interface ITimesheetImport
{
[OperationContract]
Acknowledgement ImportTimesheet(string xml, string system, Guid authenticationToken);

[OperationContract]
string ApiActive();
}

我已经阅读了很多关于自签名证书的文章,但他们似乎建议这是在 IIS 下使用,而不是在 visual studio 中使用 IIS express。

关于这个主题的任何帮助和建议都会很棒。

谢谢

最佳答案

您应该检查的第一件事是您是否能够通过https://localhost:50257/AssignmentImport.svc 浏览wsdl。 .

我认为你做不到,因为缺少行为配置。

 <service name="NetiveApi.IisHost.TimesheetImport" behaviorConfiguration="metadatadiscov">

现在命名您的服务行为,它已经覆盖了元数据的默认实现。

 <behavior name="metadatadiscov" >
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<!-- Use your own port numbers -->
<!--<add scheme="http" port="8080" />-->
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>

现在您应该可以浏览 wsdl 了。 https://localhost:50257/AssignmentImport.svcIf请不要张贴您的服务契约(Contract)以及基地址配置。

关于wcf - 使用 SSL 在 VS2015 中调试 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48428850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com