Reputation: 8406
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. Then I use these in other .NET applications. This usually works fine.
Today I have to supply an address to PHP developers so they can call the web service. I have no idea what the address of my service is!
I've tried many combinations e.g http://localhost:8010/Generic
but to no avail.
What is the URL of my endpoint for the PHP application to call
What is the URL to give to the WCF Test Client so I can check the interface.
++++++++++++++++++++++++++++++++++++++
Added this Error response from WCF Test Client after using suggestions below.
>
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.
Upvotes: 1
Views: 3039
Reputation: 16878
If PHP developers want to use SoapClient or something like that, WSDL should be published. 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/
.
You can also override wsdl address by using HttpGetUrl
parameter of ServiceMetadataBehavior
:
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
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
.
Upvotes: 3