开发者

App.config namespace issue

开发者 https://www.devze.com 2022-12-08 13:31 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消