adding a service reference to net.msmq wcf service - c#

I'm trying to add a service reference to my wcf app in visual studio.
I can do it for various bindings such as net.pipe and basichttp...
but to net.msmq binding, I get error
Here is the relevant part of my web.config:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="netMsmqBinding" exactlyOnce="false">
<security mode="None"></security>
</binding>
</netMsmqBinding>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WCF_ServiceSample.WCF_ServiceBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata />
<serviceDebug />
<serviceDiscovery />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="serviceBehavior" name="WCF_ServiceSample.WCF_Service">
<host>
<baseAddresses>
<add baseAddress="http://localhost:4000/Services/" />
<add baseAddress="net.msmq://localhost/Services/" />
</baseAddresses>
</host>
<endpoint address="mex" behaviorConfiguration="WCF_ServiceSample.WCF_ServiceBehavior"
binding="mexHttpBinding" bindingConfiguration="" name="mex_http"
contract="IMetadataExchange" />
<endpoint address="AdventureWorksServiceHttp" binding="basicHttpBinding" bindingConfiguration=""
name="basicHttpEndpt" contract="WCF_ServiceSample.WCF_Service" />
<endpoint address="AdventureWorksServiceNetMsmq"
binding="netMsmqBinding" bindingConfiguration="netMsmqBinding"
contract="WCF_ServiceSample.WCF_Service" />
</service>
</services>
</system.serviceModel>
Here is the error I get when I run my service via the wcf client:
Error: Cannot obtain Metadata from
http://localhost:9011/WCF_Service.svc 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:9011/WCF_Service.svc Metadata contains a
reference that cannot be resolved:
'http://localhost:9011/WCF_Service.svc'. The server did not provide a
meaningful reply; this might be caused by a contract mismatch, a
premature session shutdown or an internal server error.HTTP GET Error
URI: http://localhost:9011/WCF_Service.svc There was an error
downloading 'http://localhost:9011/WCF_Service.svc'. The request
failed with the error message:-- Server Error in '/' Application.
Could not find a base address that matches scheme net.msmq for the
endpoint with binding NetMsmqBinding. Registered base address schemes
are [http]. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
here is the error I get when I go to add service reference ->
net.msmq://localhost/WCF_Service.svc
then I press "Go"
The URI prefix is not recognized. The MetadataExchangeClient instance
could not be initialized because no Binding is available for scheme
'net.msmq'. You can supply a Binding in the constructor, or specify a
configurationName. Parameter name: scheme If the service is defined in
the current solution, try building the solution and adding the service
reference again.

add mex bindings as that will allow you to add proxy reference, then you can use the net.msmq bindings to do the operation.
What is "mexHttpBinding"?
https://msdn.microsoft.com/en-us/library/aa967390(v=vs.110).aspx

Related

WCF Service is not connecting to test client

I keep getting this error when I run the test client
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Cannot obtain Metadata from http://localhost:50507/Service1.svc 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:50507/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:50507/Service1.svc'. The requested service, 'http://localhost:50507/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:50507/Service1.svc There was an error downloading 'http://localhost:50507/Service1.svc'. The request failed with the error message:-- The type 'AgeCalculator.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I have already exposed the metadata of the service with the following code in the web.config file
<system.serviceModel>
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
I have looked at all current documentation and don't know what the issue is. May be a naming convention as I am brand new to WCF but not seeing this. I have scoured the internet and exposing the metadata articles to apply fixes and nothing has worked to date
Since you don't seem to be using the default port, it is best to specify the port in your service binding. Change your service definition like this:
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:50507/" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1" />
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:50507/Service1.svc"
binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>

add service reference only works with localhost wcf service

I am trying to host a svc service in my web application and I am trying to connect to it with a simple client application.
When the host is hosted in my own computer and solution, and I run the web application locally, everything works fine, meaning that I can add the reference to the service using add service reference in my client solution with http://localhost:6543/Hello.svc as the address and when I navigate to the service's url, it shows me the service's information as it should.
But when I publish my website, and I try to add the reference to my service using add service reference with http://myserver.com/Hello.svc as the address, i get the error message bleow:
There was an error downloading
'http://myserver.com/Hello.svc/_vti_bin/ListData.svc/$metadata'. The
request failed with HTTP status 404: Not Found. Metadata contains a
reference that cannot be resolved: 'http://myserverc.com/Hello.svc'.
The remote server returned an unexpected response: (405) Method Not
Allowed. The remote server returned an error: (405) Method Not
Allowed. If the service is defined in the current solution, try
building the solution and adding the service reference again.
and oddly when I navigate to myserver.com/Hello.svc, the browser starts to download the Hello.svc file instead of showing the service's details and information.
this is my website's web.config file:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WithDebug">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="HelloWorldService.HelloService" behaviorConfiguration="WithDebug">
<host>
<baseAddresses>
<add baseAddress="http://myserver/Hello.svc"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="webHttpBinding" bindingConfiguration="crossDomain"
contract="HelloWorldService.IHelloWorld" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I think I am missing something big here, but since I am new to WCF, I don't know what it is.Any help would be appreciated and I am more than happy to issue more details about my project if needed.
Thanks in advance
You need to run ServiceModel registration tool
"This command-line tool provides the ability to manage the registration of WCF and WF components on a single machine. Under normal circumstances you should not need to use this tool as WCF and WF components are configured when installed. But if you are experiencing problems with service activation, you can try to register the components using this tool."

Enabling http and https on the same service

I am writing a WCF service which contains a singe contract. I would like web clients to call the service endpoint using either http or https.
My web.config is as follows:
(Some parts have been removed for brevity)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDataService" />
<binding name="BasicHttpsBinding_IDataService" >
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DataServiceMetadataBehavior" name="DummyService.DataService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataService"
contract="DummyService.IDataService"/>
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IDataService"
contract="DummyService.IDataService" name="BasicHttpsBinding_IDataService"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceMetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" />
<add scheme="https" binding="basicHttpBinding" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
When I try to test the service using the VisualStudio test client, it gives the following error:
Could not find a base address that matches scheme https for the
endpoint with binding BasicHttpBinding. Registered base address
schemes are [http].
Everything works fine with only a single endpoint.
An endpoint consists of address, binding and contract.
http://YourBaseAddress/YourApp/YourService.svc and httpS://YourBaseAddress/YourApp/YourService.svc are different address with different schema name or protocol as well as different ports: 80 and 443 by default, so you can have both endpoints for the service, with the same basicHttpBinding, provided that the https one has a bindingConfiguration for SSL transportation as you had done. The error message is quite informative, so you need to go to IIS (or IIS Express) to make sure there's a http listener, say https binding defined after checking the "Edit Bindings" function of the Website. After you had done so, you should be able to get WSDL through httpS://YourBaseAddress/YourApp/YourService.svc?wsdl in a Web browser.
In fact, many Web services/applications like those from Microsoft and Google support both http and https through the same host name and path.

Metadata contains a reference that cannot be resolved .

Following is my WCF configuration. I published it in IIS and trying to connect to it from a Windows forms client.
<system.serviceModel>
<client />
<bindings>
<wsHttpBinding>
<binding name="BindingConfiguration">
<security>
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="BehaviorConfiguration">
<endpoint address="" binding="wsHttpBinding" name="wsBinding" contract="WCFHttps.IService1" bindingConfiguration="BindingConfiguration"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name= "BehaviorConfiguration">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
It throws an error while trying to add service reference in the test client.
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: '****/Service1.svc?wsdl'.
Content Type application/soap+xml; charset=utf-8 was not supported by service ****/Service1.svc?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'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
I have also granted read/write permissions for IIS_USRS over C:\Windows\Temp folder but still the problem persists. Can anyone suggest what's wrong here.
Thanks.
cause:
Cause of this error is simple when you try to refer the WCF service IIS tried to access C:\Windows\Temp folder. If ASP.NET or IIS_IUSER(based on the windows version) account doesn’t have access to this folder you will see this error.
Solution:
Add ASP.NET or IIS_USER account to this folder or give admin rights to the user account you are running your application.
Configuring Tracing
http://msdn.microsoft.com/en-us/library/ms733025.aspx
In my case wrong namespace was specified in web.config file. It has to be same as namespace of your .svc file:
<service name="NAMESPACE.SvcFileName">
<endpoint contract="NAMESPACE.IContractName" />
</service>
Example:
<service name="MyNameSpace.FileService">
<endpoint contract="MyNameSpace.IFileService" />
</service>
(Unrelevant tags ommited in these samples)

WCF Endpoint. Multiple Clients

I have an IIS hosted WCF webservice. It started with two consumers.
1) A WinForm test harness in the same solution to test the WCF contracts in the IDE.
2) An Asp.Net Web App that is consuming the published version.
All was working out of the box so to speak.
Then along came the 3rd consumer, an Android app. To get this consuming correctly had to decorate the WCF contracts with JSON WebGets and Webinvokes and alter the WCF Web.config to suit.
Now the original two consumers no longer work. So I need to alter Web.config and / or App.configs to get a configuration where all three work.
Focusing on the IDE first. I have the following service model section for the WCF service Web.Config.
<system.serviceModel>
<client>
<endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
bindingConfiguration="" name="jsonEndPoint"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="false" />
</system.serviceModel>
The WinForm Test harness App.config has:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttp" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttp"
contract="CouponParking.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
</system.serviceModel>
I am not experienced at configuring endpoints and the above has been based on examples and guesswork.
When I run the Test Harness the wcf Client instantiates but a call on a contract fails with :
There was no endpoint listening at http://localhost:8707/CouponParking.svc
that could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."
The inner exception is :
{"The remote server returned an error: (404) Not Found."}
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233079
InnerException: null
Message: "The remote server returned an error: (404) Not Found."
Source: "System"
StackTrace: " at System.Net.HttpWebRequest.GetResponse()\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
TargetSite: {System.Net.WebResponse GetResponse()}
I would appreciate some guidance on what I have got wrong.
Thanks
At a glance, it appears that you've mixed up client endpoints with service endpoints in your service's config file. There's no reason for client endpoints to appear in the service's config file, unless that service is itself calling another service.
Your WinForm's config file is defining a client with basicHttpBinding, but you do not expose a service endpoint with BasicHttpBinding, which is most likely the reason for the error you're getting.
I would try deleting the client endpoints in your service's config file, and add them to the <services> section, like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint address="SOAP"
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
<endpoint address="JSON"
binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</service>
</services>
Remember the ABC's of WCF: A = Address, B = Binding and C = Contract - those three items define a service.
Since you added a client that needed a different binding then your test harness or your ASP.NET application, you need to expose a second endpoint with that binding.
EDITED
As #marc_s pointed out, you'll need two distinct relative addresses. I've updated the config file to reflect that.
I've not had an occasion to use multiple endpoints myself, but I believe you'd use them this way, with the base address being provided by the location of the *.svc file:
http://localhost:8707/CouponParking.svc/SOAP
http://localhost:8707/CouponParking.svc/JSON
With the first being for the BasicHttpBinding and the second being for the WebHttpBinding.
You basically just need two separate endpoints to provide both the basicHttpBinding (a SOAP binding) and the webHttpBinding for your Android client (a REST binding).
The "base" address of your service is defined by your IIS virtual directory and where the *.svc file lives (http://localhost:8707/CouponParking.svc) - so both services will be reachable at this "base" address plus any relative address defined
So you need to configure this something like this:
<services>
<service name="CouponParkingWCF.CouponService">
<!-- define the basicHttp (SOAP) endpoint at the base address -->
<endpoint name="SoapEndpoint"
address=""
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService" />
<!-- define the REST endpoint at (base)+"/rest" -->
<endpoint name="RestEndpoint"
address="rest"
behaviorConfiguration="JsonBehavior"
binding="webHttpBinding"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
With this setup, you should be able to call your service using the basicHttpBinding (SOAP) at
http://yourServer:8707/CouponParking.svc
and you should be able to access the REST-based, JSON-enabled endpoint at
http://yourServer:8707/CouponParking.svc/rest
Both server-side endpoints will be handled by the same service code - it's just the endpoint (and the protocols that endpoints understands) that are different

Categories

Resources