locked
Metadata contains a reference that cannot be resolved: 'http://localhost/MathService/MathService.svc?wsdl'. RRS feed

  • Question

  • Hi, I have created a WCF service app which i wanting to host in IIS.

    this is the service contract and implementation on the server side:

    //IMathService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace MathService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IMathService" in both code and config file together.
        [ServiceContract]
        public interface IMathService
        {
            [OperationContract]
            int AddTwoNumbers(int a, int b);
            [OperationContract]
            SpecialNumber MultiplyTwoNumbers(int a, int b);
        }

        [DataContract]
        public class SpecialNumber
        {
            [DataMember]
            public int number { get; set;}
        }
    }

    //MathService.svc

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace MathService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MathService" in code, svc and config file together.
        public class MathService : IMathService
        {
            public int AddTwoNumbers(int a, int b)
            {
                return a + b;
            }

            public SpecialNumber MultiplyTwoNumbers(int a, int b)
            {
                return new SpecialNumber() { number = a * b };
            }
        }
    }

    I published my WCF app project into a seperate folder and created an application on IIS based on that folder: this is the published web.config file

      

    <?xml version="1.0"?>
    <configuration>

      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="basicHttp"> 
            </binding>
          </basicHttpBinding>
        </bindings>
        <services>
          <service name="MathService.MathService">
            <endpoint address="" bindingConfiguration="basicHttp" binding="basicHttpBinding"
                       contract="MathService.IMathService">
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:80/MathService"/>
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>

    </configuration>

    so if i try to use Wcftestclient or use add service reference in VS to add the service reference on a seperate client app i get this error

    Metadata contains a reference that cannot be resolved: 'http://localhost/MathService/MathService.svc?wsdl'.
    The WSDL document contains links that could not be resolved.
    There was an error downloading 'http://localhost/MathService/MathService.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/MathService/MathService.svc'.
    Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/MathService/MathService.svc.  The client and service bindings may be mismatched.
    The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
    If the service is defined in the current solution, try building the solution and adding the service reference again.

    any idea whats going on?

    im kind of new to WCF

    Saturday, June 9, 2012 8:48 AM

Answers

  • See the above error information, it seems that the binding between server and client are mismatch, for example, you are using basicHttpBinding at the server side in your web.config file, and it uses SOAP 1.1 which expects text/xml, and if you are using wsHttpBinding on the client side, it uses SOAP 1.2 which expects application/soap+xml. In addition, you can turn on WCF tracing at service side and client-side to see whether it can capture more detailed error information at underlying channel level.

    #Configuring Tracing
    http://msdn.microsoft.com/en-us/library/ms733025.aspx


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Tuesday, June 12, 2012 8:25 AM

All replies

  • The code is connecting to a service own your own computer (not a IIS server).  You either need to connect to a computer that has the service installed or install the service on your computers.  You have generated the client side of the software but don't have a Server to run the application.


    jdweng

    Saturday, June 9, 2012 10:43 AM
  • I have an IIS server running on the same machine, i have no idea what you are talking about none of what you said makes sense to me. I have trouble understanding your grammar.
    Saturday, June 9, 2012 10:50 AM
  • Can you connect to the service using your webbrowser?

    Enter the following in the URLs of a webbrowser (or click the link to open a webbrowser)

    http://localhost/MathService/MathService.svc

    Then try this link

    http://localhost/MathService/MathService.svc?wsdl

    I can't tell by the error is it can't find the service or it can't find the 'wsdl' method in the sevice.

    The Client Application is the code you posted, the Server is the URL that is executing the code.


    jdweng

    Saturday, June 9, 2012 10:59 AM
  • Can you connect to the service using your webbrowser?

    Yes it runs 

    Enter the following in the URLs of a webbrowser (or click the link to open a webbrowser)

    http://localhost/MathService/MathService.svc

    Then try this link

    http://localhost/MathService/MathService.svc?wsdl

    yes this link runs too.

    I can't tell by the error is it can't find the service or it can't find the 'wsdl' method in the sevice.

    The Client Application is the code you posted, the Server is the URL that is executing the code.


    jdweng


    Saturday, June 9, 2012 11:09 AM
  • It looks like the service is running.  Try each of these functions one at a time to see if one function works and the other doesn't work.  Make sure you set a and b to a number.  Nothing in the code you posted sets a =1 and b = 2.  You may be getting this error because you aren't sending valid numbers to the service.

            public int AddTwoNumbers(int a, int b)
            {
                return a + b;
            }

            public SpecialNumber MultiplyTwoNumbers(int a, int b)
            {
                return new SpecialNumber() { number = a * b };
            }


    jdweng

    Saturday, June 9, 2012 11:27 AM
  • See the above error information, it seems that the binding between server and client are mismatch, for example, you are using basicHttpBinding at the server side in your web.config file, and it uses SOAP 1.1 which expects text/xml, and if you are using wsHttpBinding on the client side, it uses SOAP 1.2 which expects application/soap+xml. In addition, you can turn on WCF tracing at service side and client-side to see whether it can capture more detailed error information at underlying channel level.

    #Configuring Tracing
    http://msdn.microsoft.com/en-us/library/ms733025.aspx


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Tuesday, June 12, 2012 8:25 AM
  • Hi ,

    I got the error to execute the below line.

    IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(uri);

    Following are the details to resolved the issue.

    This error is coming due to network proxy. Sometimes you checked use a proxy server for your LAN in internet explorer browser settings . So you need check whether you are using proxy server by following way.

    1) Go to internet explorer settings 

    2) Select Internet Options

    3)Go to connection Tab

    4)Click on LAN settings

    5) in LAN settings just unchecked the proxy server.

    Hope  this will help. Please mark as answer if your issue get resolve.

    Thanks

    Goutam

    Thursday, September 28, 2017 12:41 AM