WCF Errors using WCFTestClient to test a simple WCF Web Service - wcf

When I try to test the AutoLotWCFService using "wcftestclient", I get the following error. What am I doing wrong? Any insight will help. This is a simple Web Service that has wshttpbinding with interface contract and the implementation in the service. Here is the long error message: The Web.Config file has 2 endpoints - one for Web Service itself and other for metaDataExchange. Its all pretty much default stuff. I can include the code if needed - it seems I cannot attach files here.
Error: Cannot obtain Metadata from http://localhost/AutoLotWCFService/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/AutoLotWCFService/Service.svc
Metadata contains a reference that cannot be resolved: 'http://localhost/AutoLotWCFService/Service.svc'.
The remote server returned an unexpected response: (405) Method not allowed.
The remote server returned an error: (405) Method Not Allowed.
HTTP GET Error URI: http://localhost/AutoLotWCFService/Service.svc
The document at the url http://localhost/AutoLotWCFService/Service.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.
- Report from 'WSDL Document' is 'There is an error in XML document (1, 2).' -Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.
- Report from 'XML Schema' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.

I recently had this problem whilst trying to host WCF on my Windows Vista Laptop under IIS7.
I first recieved the following error : "HTTP Error 404.3 - Not Found" and one of the resolutions suggested was to "Ensure that the expected handler for the current page is mapped."
So I added a handler for the .svc file manually and defined it as a DiscoveryRequestHandler, thinking that this might help. This caused the problem you described above.
The actual resolution was to delete the handler I had added, and to run the following commands:
CD c:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\
ServiceModelReg -i
This resolved my issue and the service is working fine. I hope this might help shed some light on your problem. I can't be certain but this is probably because of the order in which I've installed the various packages on my dev laptop.

If installing compenonts doesnt work try a repair, this uninstalls and then installs.
"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r

you need to make sure that the service behaviour configuration enables has a metadata tag with httpGetEnabled="true"
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true">
&lt/behavior>
</serviceBehaviors>
In addition, make sure your service references that behavior.
<service name="blah" behaviorConfiguration="serviceBehavior">

Thanks; believe it or not the problem of at least loading the service through wcftestclient was solved when I re-registered the ASPNET in IIS with aspnet-regiis.
The next problem is to be able to invoke the methods exposed by the service through wcftestclient. What are the security issues that I have to deal with? I had to enable Anonymous login with windows auth. and still the invoke generated exceptions that pointed to something related to access violation. On searching some things point to installing certificates to be able to invoke.. Please enlighten if possible.

Try checking if service(name) in the Service Markup (right click on servicename.svc) matches the service(name) in your web.config file.
Cheers!

Related

wcf web service identity servicePrincipalName explanation required

I have a web service that uses windows integrated authentication, and it works. But only after much trial and error it only finally worked with my config file endpoint section having an identity as follows:
<identity>
<servicePrincipalName value="host/servername" />
</identity>
Where 'servername' is the name of the IIS server hosting the webservice.
If I missed it out, IIS refused it (did not even get to the end point) with 'authentication error'.
However, when I recently needed to run a program on the same server as the web service this then failed with the same error and it worked only if I completely removed the identity or changed it to 'host/localhost'.
Can somebody explain why this is because I really don't understand what the servicePrincipalName/identity is really doing other than just working.
thanks.
The name of the user you wish the service to use (execute under) are placed as value for ServicePrincipalName.
You can have much simpler reference here.

Unable to reference WSDL of WCF web service hosted on AppFabric

I have developed a WCF service and, while in Visual Studio 2010, I can import the WSDL without a problem. After I've deployed it to AppFabric, I get the WSDL, but several schema files referenced internally in the WSDL cannot be found, for some reason. I don't know if it's a configuration issue, or what. The error I get when I try to process the WSDL in Visual Studio 2010 follows below:
Metadata contains a reference that cannot be resolved:
'http://myserver.mydomain.com:9871/app_deploy/MyAppService.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://myserver.mydomain.com:9871/app_deploy/MyAppService.svc?xsd=xsd0'.
The request failed with HTTP status 502: Proxy Error ( The
specified network name is no longer available. ).
Metadata contains a reference that cannot be resolved:
'http://myserver.mydomain.com:9871/app_deploy/MyAppService.svc'.
There was no endpoint listening at http://myserver.mydomain.com:9871/app_deploy/MyAppService.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 remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the
solution and adding the service reference again.
The error is a proxy error because it goes through a proxy, but the error is because the page isn't there. I've tried accessing http://localhost:9871/app_deploy/MyAppService.svc?xsd=xsd0 at the server, but I get 404.
Why wouldn't these xsd files being found? Is it a deployment issue?
Any help would be greatly appreciated.
Man, I finally found the problem here. I needed write permission on C:\Windows\Temp for Application Pool user!

OData / WCF Data Service - HTTP 500 Error

I have created an OData/WCF service using Visual Studio 2010 on Windows XP SP3 with all current patches installed.
When I click on "view in browser", the service opens and I see the 3 tables from my EF model. However, when I add a table name ("Commands" in this case) to the end of the query string, rather than seeing the data from the table, I get an HTTP 500 error.
(This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.).
I have not only followed the examples from 2 sites, but have also tried running the sample application that the blog poster sent me (that works on his machine), and still am not having any luck.
The blog post is at Exposing OData from an Entity Framework Model
Does anyone have an idea why this is occurring and how to resolve it?
Here is the output of the "View in Browser":
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <service xml:base="http://localhost:1883/VistaDBCommandService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">
- <workspace>
<atom:title>Default</atom:title>
- <collection href="Commands">
<atom:title>Commands</atom:title>
</collection>
- <collection href="Databases">
<atom:title>Databases</atom:title>
</collection>
- <collection href="Statuses">
<atom:title>Statuses</atom:title>
</collection>
</workspace>
</service>
Update:
In an effort to get this working, I have:
Removed and re-installed IIS
Ran the %WINDIR%\Microsoft.Net\Framework\v4.0.30319\aspnet_regiis –i –enable command
Ran the %WINDIR%\Microsoft.Net\Framework\v4.0.30319\ServiceModelReg.exe -r command.
Created a new solution and followed the instructions very carefully to assure that I
didn't mess anything up.
After all of this, I am still getting the same HTTP 500 error, with no entries of any kind in the Event Viewer.
Any other ideas?
I figured out that my problem was an issue with opening the database. The way I figured it out was to add the following to the servicename.svc.cs file in the InitializeService method:
config.UseVerboseErrors=true;
Thanks to all who tried to help.
Eric
config.UseVerboseErrors=true; helped me in finding out the problem. The problem was I was using windows authentication for database connection. After changing to SQL Server Authentication everything worked fine.
Please try these debugging tips to see the actual error which happened:
Link
500 always means there was an unhandled exception in the service. Go look in the windows event log to see what that error was.
Received similar output with VS2013:
Resolved by upgrading the Entity Framework.
See answer https://stackoverflow.com/a/21028123/2116188.
You can also activate Failed Request Tracing for your Web Application in IIS
then you will get detailled trace execution in Xml files from IIS when a 500 error occurs
There is a good article here explaining how to setup Failed Request Tracing in IIS :
Using Failed Request Tracing to Trace Rewrite Rules
HTH
Cédric
If you are using SQL Server Compact data file (Like NorthWind.sdf) you need to give write file permission to IUSRS group.
Ex: If you are using NorthWind.sdf in DataDirectory i.e. YourWeb/App_Data then you need to give write permissions to _IUSRS group from IIS Console or from Windows Explorer.

WCF IIS svcutil error

I have wcf iis hosted service.
I've created standard(from vs template) wcf service and its client. At client I add ServiceReference to my wcf service. All is good. No errors, web-form for this server works too. Next step I publish my wcf service to Win2003 IIS6.0.
I successfully go to http://server:1234/Service1.svc, see web-form, can check wsdl.
But when i run: svcutil.exe http://server:1234/Service1.svc?wsdl or add service reference I've got errors:
Error: Cannot obtain Metadata from http://server:1234/Service1.svc?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error URI: http://server:1234/Service1.svc?wsdl
Metadata contains a reference that cannot be resolved:
'http://server:1234/Service1.svc?wsdl'.
The remote server returned an unexpected response: (417) Expectation failed.
The remote server returned an error: (417) Expectation failed.
At my service config I have:
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
serviceMetadata httpGetEnabled="true"/>
I can't understand problems.
Can you help me. Thanks a lot
Edit:
This answer was posted and isn't specifically useful to this question (any more) as it was based around a typo in the original question. That being said I still feel the information is useful here for people with similar problems that are likely to find this question in a search for their answer. If someone with the authority to remove answers feels that this needs removed - please feel free to remove it.
Original answer:
I'm not sure if this is helpful or not - I'm having a similar problem. Please notice that while you are accessing http://server:1234/Service1.svc ... further down in the error message it mentions that MEX endpoint is http://aurit-server:1234/Service1.svc... then, depending on how you have your bindings setup, it may be that aurit-server is not a valid endpoint for your service MEX... but server is or vice versa.
I know this isn't the full answer for you, I'm just pointing out something that I overlooked while troubleshooting my similar problem - hope it helps. I.e. aurit-server and server may not be interchangeable... they were not interchangeable in my case.
Edit:
Btw since posting this I've recieved an answer to a similar question that I posted. I strongly suggest you check it out incase it fixes your issue. Summary: It links to a blog post that details how to fix the issue I mentioned in my original 'suggestion' to you. If it helps you please make sure you vote Chesso up! (Chesso's answer to me, Blog post referenced in Chesso's answer).
I had this problem ("The remote server returned an unexpected response: (417) Expectation failed") when trying to add a service reference to a WCF service I'd deployed on another server. Turned out to be internet properties in this case.
Go to control panel -> internet properties, "Connections" tab.
Click the "LAN settings" button.
Uncheck "Automatically detect settings" and "Use automatic configuration script".
Click OK, apply / OK.
After that, I could add the service ref just fine. Worth a try if you have this problem.

Why cant my Silverlight application load data from sql on live site using WCF?

My silverlight application loads data fromt he SQL fine when I build locally but when I upload it to the live site it will just wait for data to be loaded but show no errors. It worked up until yesterday where I fear I may have changed a setting somewhere and now I cant access the data it seems?
UPDATE 1: it seems to be a problem with the service references. Everytime I update them, it will clear the ServiceReferences.ClientConfig file and then the program wont build.
UPDATE 2: I have tried cleaning and building but still the same problem.
UPDATE 3: Found an error when trying to access the service reference on the live site:
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
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.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
It sounds like your application is waiting for something, does it time out after 30 seconds? If so, check your SQL connection string.
If there is another tier between Silverlight and SQL (such as a web service), then set up a connection test to make sure that Silverlight is actually reaching SQL...
Did you accidentally replace your live web.config file? If so, try restoring the old web.config as it may have a setting that's not compatable with your server.
Re: Update 1:
Is there an error? If so please paste it. Also please paste the config file in question on pastebin and link to it from here.
Re: Update 3:
The error "This collection already contains an address with scheme http." is caused by not telling a WCF service explicitly what address you wish to bind to when there are many to chosoe from. In this case it looks like IIS is using multiple URLs, for example, consider these fictional addresses:
www.mysite.com
mysite.com
... so the WCF service has no idea which to use unless you tell it.
The solution, to this is to explictly define what URL to use with the following config lines in the web.config (within the system.serviceModel node) of your WCF service.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://www.mysite.com/SomeDirectory/MyService" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
Important:
You should update your question title to indicate that WCF is involved in the solution you have created.