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."
Related
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
I am having an issue debugging my WCF service when I set the WCF service to SSL Required in my local IIS. I am able to hit the URL correctly for my service under http/https but I cannot debug and step through the code. I received a popup box with the following text:
Unable to start debugging on the web server. The web server is not configured correctly.
When I make the service not SSL Required I am able to step through my code as expected. I am new to dealing with IIS and have gone through a number of tutorials with the same result. Any help would be awesome
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="sslBehaviorConfiguration">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="sslBindingConfiguration">
<security mode="Transport" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="SslWCFProject.Service1" behaviorConfiguration="sslBehaviorConfiguration">
<endpoint binding="wsHttpBinding" bindingConfiguration="sslBindingConfiguration" contract="SslWCFProject.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<!--<protocolMapping>
<add binding="wsHttpBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>-->
1) First, I recommend checking the IIS logs. They are usually located in the following directory: C:\inetpub\logs\LogFiles. Just go into the W3SVC prefixed folder whose modification date most closely matches when you received the error. Open the log for the correct day and see the error details.
2) If that reveals nothing, then check out the Windows Application log in your Event Viewer.
3) Do you have a certificate (e.g. self signing certificate) on your computer? Is there a trusted site issue here?
I believe I found my answer. It looks like the checkbox in IIS for the website for Require SSL is associated the client certificate and requiring a client certificate to access the service instead of the section which is below it (although I will need to select required in the future). For the post I found When this is checked off I cannot debug the service but I can attach to the process in order to debug it.
http://blogs.msdn.com/b/vijaysk/archive/2007/10/18/visual-studio-debugging-websites-that-require-client-certificates.aspx
If I am wrong please let me know. If I come across anything else I'll update this question again with my progress just to keep in documented.
I have written a application which is hosting a WCF Service.
And I try to run the application with this config.
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="MyApp.Service" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/service"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="MyApp.IService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
But it cause the application need to run as administrator.
Is it possible to run this application without admin privilege? (If possible, change the config only.) In addition, I also need to add service references in Visual Studio to write a client program. If possible, please keep the application can be added service references in Visual Studio 2010.
If you want to keep it on an HTTP binding so a nonadmin can run it, you'll need to add permissions using the command
netsh http add urlacl (see help for the rest of the params)
This will allow the user you specify to carve off a chunk of the URL-space for the machine. If you don't want to do this, you'll need to change to a different binding (netTcp, for instance) that doesn't require special privileges to listen.
This solution worked for me (using HTTP binding), open your service on this URL:
http://localhost:80/Temporary_Listen_Addresses/
Must admit that i found it on this site http://www.paraesthesia.com/archive/2010/06/11/developing-as-a-non-admin-testing-wcf-services.aspx/ after google-ing for some time...So credits to that guy.
Based on the comment to my other answer, you won't be able to do this with the built-in HTTP bindings- they're all based on HTTP.sys, which requires rights to be granted to non-admin users to register URLs. If your deployment scenario allows, consider switching to netTcpBinding instead- no permission issues there. Otherwise, you're SOL with the built-in bindings- you'd need to build a raw HTTP transport that's not based on HTTP.sys.
My WCF service was working correctly and then all of sudden it stop working. I don't think I changed anything with the configuration.
The WCF service is hosted by a windows service.
What is weird is when I add the service reference, it will identify the contract and all the methods exposed. But if I go to a browser I get a 404 error and the compiler is not creating the service. I have deleted and tried to re-add the reference with no luck
Also, my deployed application is still able to access the wcf service.
Question 1:
In a WCF windows service, should I be able to see the wsdl inside a browser (http://localhost:8080/MaestroService/mex). In IE, I am getting 400 Bad Request. I am assuming that this is the root of the problem.
Question 2:
Is there something else?
App.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="metadataAndDebug">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataAndDebug" name="MaestroServiceLibrary.MaestroService">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
name="basicHttp" contract="MaestroServiceLibrary.IMaestroService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<endpoint address="net.tcp://localhost:8888/MaestroService" binding="netTcpBinding"
bindingConfiguration="" name="netTcpBinding" contract="MaestroServiceLibrary.IMaestroService" />
<endpoint address="net.pipe://localhost/MaestroService" binding="netNamedPipeBinding"
bindingConfiguration="" name="netNamedPipeBinding" contract="MaestroServiceLibrary.IMaestroService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MaestroService" />
</baseAddresses>
</host>
</service>
</services>
Errors Compiling:
Custom tool error: Failed to generate code for the service reference 'MaestroService'. Please check other error and warning messages for details.
Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='IMaestroService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='basicHttp']
Update
I turned on the tracing and I saw this:
The message with To 'http://localhost:8080/MaestroService/mex/mex' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree. I will update this question if I figure it out.
Update V2
I went to another project inside the same solution. I was able to add the service there with no problems. I notice I was using 3.5 in the console app vs 4.0 in the wpf browser app. When I came back to report this, I noticed in my last update that it had /mex/mex even though I put http://localhost:8080/MaestroService/mex in the url . I tried just http://localhost:8080/MaestroService and it work!!!
In the end, I did end up using Migual Castro technique here, where you create the conracts and the proxy. Which was good to see how it really works and what VS is doing. But it would be good to have that day and a half back.
thanks for the suggestions everyone.
You are running as a windows service.
A windows service runs in the security context of a user account.
If the password of the user account changes or expires, the service does not run.
The first thing that you should check is: Is the service running.
I'm having a couple of issues which may be related, or may not. I noticed that when I use Add Service Reference in Visual Studio to add a reference to my data service, the reference.cs it generates does not compile. It complains about a missing namespace. I can fix it up to compile, but this happens every time I update the reference, and it's worrying on other levels too, such as "will this cause other issues".
I also noticed that when I do this, my host server (a console application hosting the data service) logs this:
An exception occurred [System.Data.Services.DataServiceException] :: The URL
representing the root of the service only supports GET requests.
This is the service config:
<service behaviorConfiguration="behaviour" name="StatsPlus.Server.HostedServices.SPDataServiceHost">
<endpoint address="svc" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8752/DataService/"/>
</baseAddresses>
</host>
</service>
And the behaviour:
<behavior name="behaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="10"/>
</behavior>
When I try to run svcutil http://localhost:8752/DataService/, I get this:
HTTP GET Error
URI: http://localhost:8752/DataService
There was an error downloading 'http://localhost:8752/DataService'.
The request failed with HTTP status 405: Method Not Allowed.
Any ideas? Much appreciated
Thanks
I think you're connecting to a wrong address. You have a base address
<add baseAddress="http://localhost:8752/DataService/"/>
and on top of that a relative endpoint address
<endpoint address="svc" binding="webHttpBinding"
so your complete URL will be the combination of the two:
http://localhost:8752/DataService/svc
Did you try to connect there??
I am not sure if you can have a "mex" metadata exchange endpoint with WCF REST services, really. I was under the impression that the client-side proxy for a WCF Data Service gets its metadata over a special URL call from the HTTP endpoint. So maybe try to remove that from your config as well (and you can't use svcutil on that service, I believe - svcutil is only for SOAP service calls, if I'm not mistaken).
Also, since you're using webHttpBinding and self-hosting, you need to add the webHttp behavior:
<behavior name="behaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="10"/>
<webHttp />
</behavior>
If you do these two steps, I think you should be able to get at your WCF Data Service. Try it and let us know!