Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5530
  • Last Modified:

Error accessing WCF using WcfTestClient when hosting on IIS

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
MeritorWabco
Asked:
MeritorWabco
  • 26
  • 16
1 Solution
 
MeritorWabcoAuthor Commented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MeritorWabcoAuthor Commented:
Microsoft WCFTestClient.exe

The WCFtestclient reads in the meta data and allows you to test basic and ws endpoints.
0
 
Bob LearnedCommented:
So, the problem you are having is with the WcfTestClient, and not the WCF service?
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
How did you publish the service to the IIS server?
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
Take a look at this MSDN article:

ASP.NET Web Application Project Deployment Overview
http://msdn.microsoft.com/en-us/library/dd394698.aspx
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
All it takes is for you to miss one step, and everything won't work correctly.
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
Can you access the hosted .svc address from a web browser (i.e. Internet Explorer), and get the test page?
0
 
MeritorWabcoAuthor Commented:
Yes I can.  I can get to the wsdl also.
0
 
MeritorWabcoAuthor Commented:
It would be cool if experts-exchange could implement some type of screen sharing or something.  
0
 
Bob LearnedCommented:
Do you have an option at the bottom of the Comment block for ScreenCast?
0
 
MeritorWabcoAuthor Commented:
Oh thats neat.
MeritorWabco-429531.flv
0
 
MeritorWabcoAuthor Commented:
I dont think so.  Just the domain of my computer.  Would that be considered sensitive?
0
 
MeritorWabcoAuthor Commented:
Ah yeah I am comfortable with what I posted. Thanks.
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
Did you switch your web service application to point to IIS through the project properties?


Screenshot.png
0
 
MeritorWabcoAuthor Commented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
What .NET version are you using?  If you have 2010, did you install SP1?
0
 
MeritorWabcoAuthor Commented:
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
 
MeritorWabcoAuthor Commented:
Same thing as before...
0
 
MeritorWabcoAuthor Commented:
0
 
Bob LearnedCommented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
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
 
MeritorWabcoAuthor Commented:
Well I did the exact same thing as what you had.  I am assuming that it is my IIS settings then.
0
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
What is the bad news, if it is working?  Is it that we didn't learn anything from this experience?
0
 
MeritorWabcoAuthor Commented:
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
 
MeritorWabcoAuthor Commented:
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
 
Bob LearnedCommented:
Don't worry about the grade with me, other than a "C", since that is hardly ever justifiable.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 26
  • 16
Tackle projects and never again get stuck behind a technical roadblock.
Join Now