Solved

Error accessing WCF using WcfTestClient when hosting on IIS

Posted on 2011-03-15
44
5,097 Views
Last Modified: 2012-05-11
I am able to connect to my wcf webservice using WcfTestClient.exe when I consume my web service using an ASP.NET web application and host on the ASP.NET development server.

But when I consume my web service using an ASP.NET application and host it on IIS I get the following errror when i try to connect using WcfTestClient.exe:

'Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.'

Any ideas why?
0
Comment
Question by:MeritorWabco
  • 26
  • 16
44 Comments
 

Author Comment

by:MeritorWabco
ID: 35141290
See my web.config.
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="TestServiceLibrary.TestService">
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="basic" binding="basicHttpBinding" contract="TestServiceLibrary.ITestService" />
        <endpoint address="ws" binding="wsHttpBinding" contract="TestServiceLibrary.ITestService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceM

Open in new window

0
 

Author Comment

by:MeritorWabco
ID: 35147410
I still haven't made any progress with this.  If anyone could help I would appreciate it.

To clarify above.  I created a WCF Service Library.  Then I created WCF service web application (thats what I was calling an ASP.NET web application) and added that previously created library as a reference to this new wcf web application.  It works when I host my service on the development server.  But when I host it on IIS I can open my service with the browser but I when I test with WCF test client I get 'Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.'
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35148739
I see multiple endpoints defined in the web.config.  Which binding are you using (MEX, Basic, or WS)?  What type of application is WcfTestClient.exe?  
0
 

Author Comment

by:MeritorWabco
ID: 35148811
Microsoft WCFTestClient.exe

The WCFtestclient reads in the meta data and allows you to test basic and ws endpoints.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35148870
So, the problem you are having is with the WcfTestClient, and not the WCF service?
0
 

Author Comment

by:MeritorWabco
ID: 35149010
I am honestly not sure.  When I host my WCF service application in ASP.NET development server I can use the address provided and browse to it using the browser and then connect to my service using WcfTestClient.  But when I host it in IIS i can browse to my service using the browser no problem but when I try to connect to it then using the WcfTestClient I get that error above.  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35149061
I haven't ever worked with the WcfTestClient, and I see that it has somethings that it can't support.

WCF Test Client (WcfTestClient.exe)
http://msdn.microsoft.com/en-us/library/bb552364.aspx

Features supported by WCF Test Client

The following is a list of features supported by WCF Test Client:

Service Invocation: Request/Response and One-way message.

Bindings: all bindings supported by Svcutil.exe.

Controlling Session.

Message Contract.

XML serialization.

The following is a list of features not supported by WCF Test Client:

Types: Stream, Message, XmlElement, XmlAttribute, XmlNode, types that implement the IXmlSerializable interface, including the related XmlSchemaProviderAttribute attribute, and the XDocument and XElement types and the ADO.NET DataTable type.

Duplex contract.

Transaction.

Security: CardSpace , Certificate, and Username/Password.

Bindings: WSFederationbinding, any Context bindings and Https binding, WebHttpbinding (Json response message support).

I usually work with more complex WCF services, that don't lend themselves well to testing with WcfTestClient.  I see where the tool tries to read the server configurations, and test each one.  Are you adding a service reference to your ASP.NET web site project, and consuming the WCF service through that proxy, or trying to use WcfTestClient for that?
0
 

Author Comment

by:MeritorWabco
ID: 35149207
Hosting the WCF service library in ASP.NET web site and then trying to host that site in IIS.

See my screenshots attached. It includes results from hosting in development server and IIS. Also how my webservice is referenced.

 Screen-shots.zip
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35149305
Simple questions first, "Is the IIS service started, and the web service running?"  Can you add a service reference to the service running on IIS host?
0
 

Author Comment

by:MeritorWabco
ID: 35149375
From what I can tell the web service is started and running.  I am making that assumption because I added my asp.net application (that has the reference to the service library) to the Default Web Site in IIS and it says that it has been started.

I can't add the service reference to the service running on the IIS host. I tried with WcfTestClient and then just a simple winforms application.  

Both failed with the same message...
'Metadata contains a reference that cannot be resolved: 'http://hebjaz002.na.autoedir.com/TestServiceSite/test.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://hebjaz002.na.autoedir.com/TestServiceSite/test.svc?xsd=xsd0'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://localhost/TestServiceSite/test.svc'.
There was no endpoint listening at http://localhost/TestServiceSite/test.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.'
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35149426
How did you publish the service to the IIS server?
0
 

Author Comment

by:MeritorWabco
ID: 35149525
Sorry I am very new with WCF and IIS so I hope I am understanding your question. But what I did was after I added my service library to my asp.net site I was able to launch my .svc file in the browser fine in visual studio.  And then tested using WCF test client when it was being hosted on the ASP.NET development server.

So then I thought it was working fine.  So I went into IIS and right clicked my Default Web Site and selected 'Add Application'.  Gave it a name and pointed to the directory.  I had to change the security settings for the directory that my website was being hosted and had to add the IIS user IIS_IUSRS and give permissions.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35149630
Take a look at this MSDN article:

ASP.NET Web Application Project Deployment Overview
http://msdn.microsoft.com/en-us/library/dd394698.aspx
0
 

Author Comment

by:MeritorWabco
ID: 35149786
I shall try!! to deploy my web application a differnt way to IIS.  The way I did it was similar to a pluralsight.com demo I was working off of and it worked fine for them. Frustrating!! :)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35149835
All it takes is for you to miss one step, and everything won't work correctly.
0
 

Author Comment

by:MeritorWabco
ID: 35150347
Ok well....I tried to right click my web site and publish to IIS to the Default Web Site and same exact error when I try to add the service reference to WcfTestClient or my winforms application.

See my process in the attached word document.

 PROCESS.docx
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35150422
Can you access the hosted .svc address from a web browser (i.e. Internet Explorer), and get the test page?
0
 

Author Comment

by:MeritorWabco
ID: 35150433
Yes I can.  I can get to the wsdl also.
0
 

Author Comment

by:MeritorWabco
ID: 35150609
It would be cool if experts-exchange could implement some type of screen sharing or something.  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35150638
Do you have an option at the bottom of the Comment block for ScreenCast?
0
 

Author Comment

by:MeritorWabco
ID: 35150770
Oh thats neat.
MeritorWabco-429531.flv
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:MeritorWabco
ID: 35150972
I dont think so.  Just the domain of my computer.  Would that be considered sensitive?
0
 

Author Comment

by:MeritorWabco
ID: 35151085
Ah yeah I am comfortable with what I posted. Thanks.
0
 

Author Comment

by:MeritorWabco
ID: 35151129
Well back to my sitiuation.  My overall goal with this is to have a desktop application communicate to a web database.  I was going to use a web service to communicate between the desktop application and the web database.

First off. Is this the right thing to do?  My desktop application isn't on the same network as my database.

If it is, my goal was just to create a small easy helloworld type of wcf service that I could host on IIS on my computer and then connect to it from a desktop application.  My service works fine when I host it as a windows service or using wcfsvchost or on the asp.net development server, but as soon as I drop it into IIS I get this error.  Since I am having so much trouble would it make sense if I start all over?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35151184
1) This might be a learning experience, which is easier to work with when it is broken.

2) You would need to determine how long you could afford to spend troubleshooting a problem.

3) "Repaving" is the process of starting over, and putting a "clean" surface down over the top of a "road" that is a mess.  It can be very beneficial for simple services, but a headache for more complex services.
0
 

Author Comment

by:MeritorWabco
ID: 35151241
I completely understand what you are saying. My service is extremely simple so repaving wouldn't take that long. The problem is I would have to repave a different way than what I did. Everything I keep reading is telling me to setup my web.config the same way with exposing the metadata endpoint along with the service behavior.

I just don't know why it works fine when hosting on asp.net development server and not iis. Its the same machine.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35151691
Did you switch your web service application to point to IIS through the project properties?


Screenshot.png
0
 

Author Comment

by:MeritorWabco
ID: 35151692
When I use svcutil.exe I get the following

C:\Program Files\Microsoft Visual Studio 10.0\VC>svcutil.exe http://hebjaz002.na
.autoedir.com/TestServiceSite/test.svc?wsdl
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'http://hebjaz002.na.autoedir.com/TestServi
ceSite/test.svc?wsdl' using WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot obtain Metadata from http://hebjaz002.na.autoedir.com/TestServiceS
ite/test.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://hebjaz002.na.autoedir.com/TestServiceSite/test.svc?wsdl

    Metadata contains a reference that cannot be resolved: 'http://hebjaz002.na.
autoedir.com/TestServiceSite/test.svc?wsdl'.

    There was no endpoint listening at http://hebjaz002.na.autoedir.com/TestServ
iceSite/test.svc?wsdl that could accept the message. This is often caused by an
incorrect address or SOAP action. See InnerException, if present, for more detai
ls.

    The remote server returned an error: (404) Not Found.


HTTP GET Error
    URI: http://hebjaz002.na.autoedir.com/TestServiceSite/test.svc?wsdl

    The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - Root element is missing.

If you would like more help, type "svcutil /?"
0
 

Author Comment

by:MeritorWabco
ID: 35151846
Ok here is what I did.  I created an entirely new solution.

File - New Project - WCF - WCF Service Application

Gave it a name (WcfServiceTest1) and then saved it to my desktop.

Didn't change any of the default template but I right clicked the Service1.svc file and chose to view in browser.  The ASP.NET Development server launched and I was able to view the .svc file in the browser and where it has the Test classes and says Service1 Service at the top in the page.

Then I launched WcfTestClient.exe while the development server was still running and was able to add my service with no errors.

Stopped my development server.

Went to my solution properties and selected Web tab.  Selected Use Local IIS Web Server.  Selected 'Create Virtual Directory' button (got a created successfully message). Pressed OK.

Launched IIS.  I saw my application WcfServiceTest1 under Default Web Site.  Selected WcfServiceTest1.  Changed to content view.   Right-clicked Service1.svc and chose browse.  The service came up in my default browser.  So I took the address in the address bar (http://localhost/WcfServiceTest1/Service1.svc)  and used that to add my service to WcfTestClient.exe and while it was adding I got the same error.

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

Error: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: Schema with target namespace 'http://tempuri.org/' could not be found.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService1']Error: Cannot import wsdl:bindingDetail: 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='IService1']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_IService1']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_IService1']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='Service1']/wsdl:port[@name='WSHttpBinding_IService1']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.






0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35151860
What .NET version are you using?  If you have 2010, did you install SP1?
0
 

Author Comment

by:MeritorWabco
ID: 35151942
The project I just created was using .Net Framework 4 on VS 2010.  I have not installed SP1.  I will do it and then let you know what the results are.
0
 

Author Comment

by:MeritorWabco
ID: 35155736
Same thing as before...
0
 

Author Comment

by:MeritorWabco
ID: 35160355
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35161736
I am usually the beneficiary of a working WCF service, that others set up, and I don't get to work on this side very much.  That makes this a perfect question for me to figure out the steps to get this working.  I did get a working WCF service, with a mix of configuration working using the WCF config (right-clicking on the web.config), and manual editing, but I am still getting a "405 Method not allowed", and I have no idea what that means.  I was able to get the WCF service to work with the WcfTestClient (thanks for that BTW), by building the solution, creating a new service reference (WcfService1.Service1), setting multipleSiteBindingsEnabled="false", binding to wsHttpBinding.

<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfService1.Service1">
        <endpoint address="http://localhost/WcfService1" binding="wsHttpBinding"
          bindingConfiguration="" name="Default" contract="WcfService1.IService1" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="Default" />
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Open in new window

Snapshot.png
0
 

Author Comment

by:MeritorWabco
ID: 35164925
So you did basically the same project I did on 03/16/11 01:30 PM, ID: 35151846 and changed your web.config to reflect what you have above?  And even though you couldn't get it to work in the browser you got it to work with wcftestclient.exe?  And this was hosted in IIS?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35169562
Yes, I neglected to mention, that I changed the web site to be hosted on IIS.  I tried both my Windows XP 5.1 IIS, and Express Edition 7.5, and both gave me the aforementioned 405 error.
0
 

Author Comment

by:MeritorWabco
ID: 35171844
Well I did the exact same thing as what you had.  I am assuming that it is my IIS settings then.
0
 

Author Comment

by:MeritorWabco
ID: 35184741
Well good news and bad news...
I essentially gave up and reformatted my computer.  Installed everything I needed vs, iis, .net 4, etc etc...  I created the same template wcfservice project as above and well it worked. Don't know why it must of been some type of configuration to IIS that I must of changed or something.  I did try to uninstall IIS and reinstall it so maybe it was something else.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 35185679
What is the bad news, if it is working?  Is it that we didn't learn anything from this experience?
0
 

Author Comment

by:MeritorWabco
ID: 35188984
Yeah I didn't learn anything other than to fix a pc reformat or restart!! which I already knew :).  Atleast I was able to narrow it down to the something with the way IIS was installed or configured even though I had uninstalled and reinstalled a couple times before having to reformat.
0
 

Author Closing Comment

by:MeritorWabco
ID: 35189023
I wasn't completely sure how to grade this since we weren't able to identify the exact root cause and fix it completely so I hope I graded this right.  But you were very helpful and persistant in helping me and I really appreciate it.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35189082
Don't worry about the grade with me, other than a "C", since that is hardly ever justifiable.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IIS Issue 7 85
Default web.conf for all sites. 5 49
Error viewing ASP page 12 94
IIS 7.5 to 8.0 6 72
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now