如何在浏览器中查看我的WCF端点

时间:2013-11-27 12:32:34

标签: .net wcf

我有这个:

_host = new ServiceHost(typeof(FloCommunicationHubWebServiceIo), new[] { new Uri("http://localhost:8010/") });

 // Create basicHttpBinding endpoint at http://localhost:8080/Beam.Flo2.CommunicationHub/
 _host.AddServiceEndpoint(typeof(FloCommunicationHubWebServiceIo), new BasicHttpBinding(), "Generic");

 // Add MEX endpoint at http://localhost:8080/MEX/
 var behavior = new ServiceMetadataBehavior { HttpGetEnabled = true };
 _host.Description.Behaviors.Add(behavior);
 _host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");

  _host.Open();

通常我使用svcutil.exe工具为app.config创建WebServiceProxy.cs文件和设置。然后我在其他.NET应用程序中使用它们。这通常很好。

今天我必须为PHP开发人员提供一个地址,以便他们可以调用Web服务。我不知道我的服务地址是什么!

我尝试了许多组合,例如http://localhost:8010/Generic,但无济于事。

我要调用的PHP应用程序的端点的URL是什么

提供给WCF测试客户端的URL是什么,以便我可以检查界面。

++++++++++++++++++++++++++++++++++++++

在使用以下建议后,从WCF测试客户端添加了此错误响应。

>

 Error: Cannot obtain Metadata from http://localhost:8010/Generic?wsdl 
> 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: `http://localhost:8010/Generic?wsdl` 
> 
> Metadata contains a reference that cannot be resolved:
> 
> '`http://localhost:8010/Generic?wsdl`'.  Content Type
> application/soap+xml; charset=utf-8 was not supported by service
> `http://localhost:8010/Generic?wsdl.` 
> 
> The client and service bindings may be mismatched.  The remote server
> returned an error: (415) Cannot process the message because the
> content type 'application/soap+xml; charset=utf-8' was not the expected type
> 'text/xml; charset=utf-8'..HTTP GET Error URI:
> `http://localhost:8010/Generic?wsdl`  There was an error downloading
> '`http://localhost:8010/Generic?wsdl`'.  The request failed with HTTP
> status 400: Bad Request.

1 个答案:

答案 0 :(得分:2)

如果PHP开发人员想要使用SoapClient或类似的东西,那么应该发布WSDL。为此,只需将?wsdl添加到服务端点,即它应为http://localhost:8010/?wsdl,服务地址为http://localhost:8010/

您还可以使用HttpGetUrl的{​​{1}}参数覆盖wsdl地址:

ServiceMetadataBehavior

现在它将在var behavior = new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = http://myservername:8010/Generic }; _host.Description.Behaviors.Add(behavior);

上提供

但我建议不要混用基址和相对地址,因此工作示例可能如下所示:

http://myservername:8010/Generic?wsdl

然后在var _host = new ServiceHost(typeof(FloCommunicationHubWebServiceIo), new[] { new Uri("http://localhost:9010/Generic") }); _host.AddServiceEndpoint(typeof(FloCommunicationHubWebServiceIo), new BasicHttpBinding(), ""); var behavior = new ServiceMetadataBehavior { HttpGetEnabled = true, }; _host.Description.Behaviors.Add(behavior); _host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX"); _host.Open(); 公开WSDL,而调用的端点只是http://localhost:9010/Generic?wsdl