简体   繁体   English

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

[英]How do I view my WCF endpoints in a browser

I have this: 我有这个:

_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();

Usually I use the svcutil.exe tool to make a WebServiceProxy.cs file and settings for app.config. 通常我使用svcutil.exe工具为app.config创建WebServiceProxy.cs文件和设置。 Then I use these in other .NET applications. 然后我在其他.NET应用程序中使用它们。 This usually works fine. 这通常很好。

Today I have to supply an address to PHP developers so they can call the web service. 今天我必须为PHP开发人员提供一个地址,以便他们可以调用Web服务。 I have no idea what the address of my service is! 我不知道我的服务地址是什么!

I've tried many combinations eg http://localhost:8010/Generic but to no avail. 我尝试了很多组合,例如http://localhost:8010/Generic但无济于事。

What is the URL of my endpoint for the PHP application to call 我要调用的PHP应用程序的端点的URL是什么

What is the URL to give to the WCF Test Client so I can check the interface. 什么是提供给WCF测试客户端的URL,以便我可以检查界面。

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

Added this Error response from WCF Test Client after using suggestions below. 在使用以下建议后,从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.

If PHP developers want to use SoapClient or something like that, WSDL should be published. 如果PHP开发人员想要使用SoapClient或类似的东西,那么应该发布WSDL。 To do that, just add ?wsdl to your service endpoint so it should be http://localhost:8010/?wsdl and service address will be http://localhost:8010/ . 为此,只需将?wsdl添加到服务端点,使其为http://localhost:8010/?wsdl ,服务地址为http://localhost:8010/

You can also override wsdl address by using HttpGetUrl parameter of ServiceMetadataBehavior : 您还可以使用ServiceMetadataBehavior HttpGetUrl参数覆盖wsdl地址:

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

so now it will be available at http://myservername:8010/Generic?wsdl 现在它将在http://myservername:8010/Generic?wsdl

But I suggest not to mix base and relative addresses, so working example might look like: 但我建议不要混合基址和相对地址,因此工作示例可能如下所示:

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();

And then WSDL is exposed at http://localhost:9010/Generic?wsdl , and endpoint to call is just http://localhost:9010/Generic . 然后WSDL暴露在http://localhost:9010/Generic?wsdl ,而要调用的端点只是http://localhost:9010/Generic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM