Confused using hostname in WSDL file in C # web service

I created a WCF web service in C # deployed to a Windows Service EXE, which works basically the way I want. I use it myself (not as part of IIS).

To make the WSDL file available to the calling Java web service, I added ServiceMetadataBehavior to the host creation. i.e:

ServiceHost host = new ServiceHost(typeof(MyService)); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); host.Open(); 

All this worked fine until I transferred my service to another server with a different host name. When I connect to WSDL (http: // prod-server: 55000 / MyService? Wsdl), I see that the host name of the development server is hardcoded in WSDL.

Here is a WSDL snippet as shown in the browser:

 <wsdl:definitions name="MyService" targetNamespace="http://tempuri.org/"> <wsdl:import namespace="MyProject.ServiceContracts" location="http://dev-server:55000/MyService?wsdl=wsdl0"/> <wsdl:types/> 

I checked all the C # code in the project, and the name of the development server is not encoded anywhere.

In the App.config file, I have the following defined:

 <system.serviceModel> <services> <service name="MyService"> <endpoint address="http://localhost:55000/MyService" binding="basicHttpBinding" bindingConfiguration="" contract="MyProject.ServiceContracts.IMyInterface" /> <host> <baseAddresses> <add baseAddress="http://localhost:55000/MyService" /> </baseAddresses> </host> </service> </services> 

I expect this to replace the localhost machine name, but it is saved as the name of the development window in which the service was originally created / deployed. Am I mistaken?

I also considered the possibility of explicitly specifying the path to my WSDL file, but from what I can do, this can only be done when hosting the service in IIS.

Finally, and purely out of curiosity, I wonder if the actual WSDL file (the physical file on disk that I mean) is actually being created, or is it dynamically displayed with every request?

+6
source share
2 answers

It is created dynamically, not every IIRC call, but on the first request to the metadata endpoint. I'm not sure why you see the name of your DEV server on a machine other than DEV, but since you only specify localhost in your endpoint address, it is going to resolve DNS using the main network address for the server. You might want to add useRequestHeadersForMetadataAddress to the configuration so that it actually uses the DNS that accesses the service.

+3
source

With WCF, WSDL is dynamically generated.

I had this problem several times in the WCF 3 / 3.5 service when I needed to send WSDL to someone in a file. I usually save the files (usually there are 3 for the service, wsdl for the service, xsd for your types and xsd for the .net types, but your mileage may vary), then manually update the wsdl import to link the other two files relative to the wsdl file, and then send all three files.

wsdl:service , wsdl:port and soap:address will still refer to the dev server, but most ws accounts for this account also allow the developer to configure the endpoint.

+3
source

Source: https://habr.com/ru/post/889544/


All Articles