简体   繁体   中英

App.config namespace issue

I'm working with an interface generated by from a wsdl, and I'm running into an issue when trying to host my service as a Windows Service.

The following line appears above the interface. Unless I change it from

    [System.ServiceModel.ServiceContractAttribute(Namespace="http://xxxxxx.com/", ConfigurationName="IService")]

to

    [System.ServiceModel.ServiceContract]

I can't start the Windows service that hosts my program (the error log in the event viewer says the contract IService could not be found in the list of contracts implemented by Service.) I'm listing the endpoint my app.config file as follows:

   endpoint address=""
              binding="basicHttpBinding"
              contract="Service.IService"

This also happens when I change the contract to " http://xxxxxxx.com/IService " as it appears in the ServiceContractAttribute. Any ideas about how I can fix this?

The service portion of the config file:

<service name="Service.Service"
           behaviorConfiguration="myServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/Service"/>
      </baseAddresses>
    </host>
    <endpoint address=""
              binding="basicHttpBinding"
              contract="Service.IService" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="Service.IService" />

  </service>
<behaviors>
  <serviceBehaviors>
    <behavior name="myServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

The contract attribute of the endpoint element in config needs to match the value of the ConfigurationName property of the ServiceContractAttribute in the code. So in your case just change the config so that it reads contract="IService" and you should be good.

It appears that it can't find the endpoint. Have you used a terminal to interrogate the endpoint to see if it is responding at the supplied address?

"itowlson" is most likely on the right track with his comment - your original service contract defines a configuration name:

[ServiceContract(Namespace="http://xxxxxx.com/", 
                 ConfigurationName="IService")]

but there is no such service configuration in your config section.

Try changing this:

<service name="Service.Service"

to

<service name="IService"

(or alternatively, change the ServiceContract to:

[ServiceContract(Namespace="http://xxxxxx.com/", 
                 ConfigurationName="Service.Service")]

These two names need to match! Or simply leave out the configuration name from the service contract:

[ServiceContract(Namespace="http://xxxxxx.com/")]

and in this case, the service config will be found based on the Namespace.ServiceClassName pattern of the service class that actually implements the service contract.

Either way, you need to make sure the information in the ServiceContract attribute and the config file match up.

Marc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM