I am new to WCF and windows mobile development. I am trying to create an occasionally connected application that utilizes the MSFT sync framework and this requires the use of a WCF service.
I have a visual studio project containing my smart device project, a WCF Service Library project, and a WCF Service website project.
The service is hosted fine on my local machine not using IIS and I can access it at http://localhost:55149/ElectricReadingServiceSite/ElectricReading.svc
However when I add it to IIS it gives me an http 404 resource cannot be found error. I cannot figure out why it thinks the resource is not there.
Here is my web.config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="MiddleTierServiceLibrary.ElectricReadingCacheSyncService"
behaviorConfiguration="MiddleTierServiceLibrary.ElectricReadingCacheSyncServiceBehavior">
<endpoint
address=""
binding="basicHttpBinding"
contract="MiddleTierServiceLibrary.IElectricReadingCacheSyncContract">
<identity>
<dns value="10.104.238.123"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MiddleTierServiceLibrary.ElectricReadingCacheSyncServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
My ElectricReading.svc looks like this:
<%# ServiceHost Language="C#" Debug="true"
Service="MiddleTierServiceLibrary.ElectricReadingCacheSyncService" %>
Any help is greatly appreciated!
EDIT: Are there any tools or steps I can take to get a better idea of what is going wrong? The 404 error does very little to help me.
There can be a number of reasons to why this could be happening.
Some of them might include:
Make sure you uploaded the assembly in the Bin folder
You have set up a website on IIS, but you are not accessing it with
the correct address(make sure the port is correct)
Your application pool is not set up for the website(if you are using
.NET 4.0 you need to set the applictation pool to version 4.0) In IIS manager go to ApplicationPools and set the pool to the version of .NET that you are using
Try using Fiddler. It should log the calls it makes and thus give you a little more detail on what it is not finding.
Related
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."
I have made a simple WCF service, and it´s working like a charm in my developer environment. But now I'm moving it to my test server (AZURE) and i can´t get the endpoint address correct. The IIS is up and running, and the service is working locally on the test server.
When I try to test the service in WCF Test client, I receive an error when I try to invoke that the endpoint is incorrect:
There was no endpoint listening at mypathattestserver/Service1.svc
that could accept the message. This is often caused by an incorrect
address or SOAP action. See InnerException, if present, for more
details.
This is my web.config:
<services>
<service behaviorConfiguration="Test.Service1Behavior" name="Test.tfn">
<endpoint address="" binding="basicHttpBinding" contract="Test.IService1">
<identity>
<dns value="http://mypathattestserver.cloudapp.net/service1.svc"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Test.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
I would suggest the following steps:
Check the service with another client. SoapUI is a very good web service client. If the service responds to SoapUI then the problem is on your client
If the server is fine and the problem is at your client, remove the reference looking at the specific server and add it again.
Finally, check your firewalls. If the system plays fine by having the client and the server on the same machine, the firewalls could be a problem when the server is located on another machine.
Hope I helped!
This is my first time using WCF. It was very easy to develop the application however it's turning me nuts to deploy on IIS.
I've tried everything to deploy it, however the client started throwing unauthorized user exception (or something like that) to an Undefined exception (after countless changes in web.config file and app.config file).
I'm back to the default configurations which work fine in VS (cassini).
Any quick pointers or some link to a detailed tutorial would be much appreciated.
Thanks in advance
<system.serviceModel>
<services>
<service behaviorConfiguration="MBTService.Service1Behavior"
name="MBTService.MBTService">
<endpoint address="" binding="wsHttpBinding" contract="MBTSTBO.IMBTService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MBTService.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Not specific to your case, however WCF Tracing is generally a really good tool to diagnose WCF configuration problems. You can see here how you can configure WCF tracing, it is really simple, the WCF runtime will basically emit some information into a .svclog file
Then you can analyze the log with the Service Trace Viewer Tool (it is in All Programs->Visual Studio 2010->Microsoft Windows SDK Tools), and see what went wrong during specific requests, it gives much more information than the exception messages.
Jonny,
This is a long shot but once I had the same problem (unauthorized access) and the problem was that some files (downloaded from a webmail) was blocked by windows. As soon I unblocked these files the web service started to work fine.
Hope it helps.
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.