How to replace Machine Name with Domain name in WCF Service - wcf

I'm get Machine Name in the WCF proxy and getting below exception while invoking WCF service
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://MyDomine.com/TCIService/TCIService/TCIService.svc?wsdl
The document was understood, but it could not be processed. - The
WSDL document contains links that could not be resolved. - There was
an error downloading
'http://MyMachine.Name/TCIService/TCIService/TCIService.svc?xsd=xsd0'.
- The remote name could not be resolved: 'MyMachineName'
Can any one please help me fix this issue. And below is my web.config
<system.serviceModel>
<services>
<service name="MyService.TCIService.TCIService" behaviorConfiguration="MyServiceBehaviour" >
<endpoint address="Account" binding="basicHttpBinding" contract="MyService.TCIContract.IAccount" >
</endpoint>
<endpoint address="Location" binding="basicHttpBinding" contract="MyService.TCIContract.ILocation" >
</endpoint>
<endpoint address="Camera" binding="basicHttpBinding" contract="MyService.TCIContract.ICamera" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
</endpoint>
<!--<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/"></add>
</baseAddresses>
</host>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

Thanks for your response Tom.
I fixed this issue using
<behavior name="MyServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<useRequestHeadersForMetadataAddress />
</behavior>

Related

Add Service Reference to Old Service

I have a need to hook into an old service that is running via a Windows Service that launches a service host through HTTP at runtime. I can't seem to find out how to get my 'Add Service Reference" to work. I know the service is running as the log file shows that. Here's the config entries for the service:
<system.serviceModel>
<bindings />
<services>
<service behaviorConfiguration="blah.blah.WCF_Service.EngineServiceBehavior" name="blah.blah.WCF_Service.EngineService">
<endpoint address="http://localhost:8455/EngineService/" binding="basicHttpBinding" bindingConfiguration="" name="Engine" bindingName="EngineBinding" contract="blah.blah.IEngineService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="Mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8455/EngineService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="blah.blah.EngineServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
It has a mex endpoint being set, but I can't see how to construct the url to get the service information.
Any thoughts?
looks like you need some details to add service reference.
in your project, right-click 'References' and select 'Add service reference ...' and enter the address John Saunders mentioned. and then click 'Go'.

I'm not able to run WCF service on IIS 5.1

I have WCF service that works fine on VS2008's Development Server, but after I deployed it on IIS 5.1 and ran the following error message comes up:
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
The appropriate section in web.config file looks as following:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Parus.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Parus.ServiceBehavior" name="Parus.Service">
<endpoint address="" binding="basicHttpBinding" contract="Parus.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I've tried to follow this article:
http://blogs.msdn.com/b/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx
But it's not working.
Does anybody know to resolve this issue?
Goran

Metadata doesn't appear

I'm trying to create a WCF service, but the metadata doesn't appear, i try:
<system.serviceModel>
<services>
<service
name ="MyNamespace.IMyContract"
behaviorConfiguration="mex">
<endpoint
address = ""
binding = "wsHttpBinding"
contract = "MyNamespace.IMyContract"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
I try to access with http://MyServer/receptor.svc but shows that Metadata publishing for this service is currently disabled. and http://MyServer/mex shows 404, why? What am i doing wrong?
OBS1: i publish my service in IIS7.5 on Windows 7.
OBS2: if i remove behaviorConfiguration="mex" the metadata works, but with basicHttpBinding not with wsHttpBinding.
I forget to put:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />

what is the "behaviorConfiguration" attribute of service?

what is the "behaviorConfiguration" attribute of service?
<services>
<service name="WcfServiceNetMSMQ.Service1" behaviorConfiguration="WcfServiceNetMSMQ.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8010/WcfServiceNetMSMQ/Service1/" />
</baseAddresses>
</host>
<endpoint address ="net.msmq://localhost/private/myqueue" binding="netMsmqBinding" contract="WcfServiceNetMSMQ.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
There are 3 important sections when you configure a WCF service.
1) Defining the Services:
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
<endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
<endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
</service>
</services>
NOTE the value of behaviorConfiguration is a reference to a section further on in the config see below...
2) Defining the 'Service Behaviours'
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
3) Defining the 'Endpoint Behaviours'
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
All 3 sections are the basics for what you need to set up a service (although this can be done programatically).
With regard to your question the behaviorConfiguration section relates to point 2 and 3 in my points above. Its where you lay out the sort of actions you want your service to have. for example above I have said that I want to allow MetaData to be published. This will essentially create a WSDL which describes the service.
The full config is here:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<!--Set up the service-->
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
<endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
<endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
</service>
</services>
<!--Define the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
It is a reference to another configuration section:
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceNetMSMQ.Service1Behavior">
</behaviors>
</serviceBehaviors>
</behaviors>
Where this section contains some global configuration for the whole service.
here's an example of it, it carries some properties of the connection of the service.
<serviceBehaviors>
<behavior name="WcfServiceNetMSMQ.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
Notice that the name in this service behavior corresponds to the one you specified earlier.
Hope that helps.
You will get this error with Behavior name is not setup correctly.
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://blabla.com/WebService/Processor.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service 'http://blabla.com/WebService/Processor.svc'. 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'..
If the service is defined in the current solution, try building the solution and adding the service reference again.

How to change address of WSDL?

I host simple WCF service in IIS in web application.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SimpleServiceBehavior" name="SimpleService">
<endpoint address="" binding="basicHttpBinding" contract="ISimpleService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
When I run service hosted on http://projects.mydomain.com/application/SimpleService.svc it shows default service page with link to WSDL:
svcutil.exe http://terminal.mydomain.local/application/SimpleService.svc?wsdl and so on
Clients can create service reference but fail to execute methods because cannot resolve host name terminal.mydomain.local
The question is why server name is its local name 'terminal.mydomain.local' instead of 'projects.mydomain.com' ?
I found answer: http://forums.asp.net/p/1096811/1659596.aspx
I needed to change host headers.