你是在类库项目里引用了WebService了吧?然后Web层调用类库?要在web层的配置文件中添加类库的App.Config里引用信息的

解决方案 »

  1.   

    那要在web层的配置文件中哪个位置添加类库的App.config里的信息?
      

  2.   

    <configuration>下面添加以下节点<system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="WSWorkManagerSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://172.16.100.168:8099/WSWorkManager.asmx" binding="basicHttpBinding" bindingConfiguration="WSWorkManagerSoap" contract="ws.WSWorkManagerSoap" name="WSWorkManagerSoap" />
        </client>
      </system.serviceModel>
      

  3.   

    不行你结贴干啥?web.config里加了配置文件还不行啊?
      

  4.   

    你把主工程引用System.ServiceModel就可以运行了!
      

  5.   

    楼主所说的我一行行比较后发现都有。
    以下是我的配置文件:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="MobileCodeWSSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>
                    </binding>
                </basicHttpBinding>
                <customBinding>
                    <binding name="MobileCodeWSSoap12">
                        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                            messageVersion="Soap12" writeEncoding="utf-8">
                            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        </textMessageEncoding>
                        <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                            useDefaultWebProxy="true" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"
                    binding="basicHttpBinding" bindingConfiguration="MobileCodeWSSoap"
                    contract="ServiceReference1.MobileCodeWSSoap" name="MobileCodeWSSoap" />
                <endpoint address="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"
                    binding="customBinding" bindingConfiguration="MobileCodeWSSoap12"
                    contract="ServiceReference1.MobileCodeWSSoap" name="MobileCodeWSSoap12" />
            </client>
        </system.serviceModel>
    </configuration>
      

  6.   

    照楼上fangyuantdy 的说话是应该可以解决问题的,如果不行,就是你类库项目的服务配制文件本来就有问题,删掉了配制文件,重新引用服务
      

  7.   

    我也碰到了这个问题:“在 ServiceModel 客户端配置部分中,找不到引用协定“IPartsHistory”的默认终结点元素。这可能是因为未找到应用程序的配置文件,或者是因为客户端元素中找不到与此协定匹配的终结点元素。”我的情况是:通过SvcUtil.exe生成的客户端代码和配置文件,问题就是出现在这个客户端的配置文件上,
    第一:文件名一定要是App.config;第二:endpoint的name属性值,在代码实例化时要一致。
      

  8.   

    有用 完全正确,因为你web层应用的只是类库项目中的DLL,没有对于的app.Config配置信息,所以类库中任何调用配置文件的信息最好是调用web层的config信息。
      

  9.   

    一定要把你的output.config改名成:app.config
    然后:
    可能你的app.config中有类似这样的情况
    <client>
                <endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IPersonService" contract="IPersonService"
                    name="BasicHttpBinding_IPersonService" />
                <endpoint address="http://sh-maweina.snda.root.corp/Service1.svc/basic"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPersonService"
                    contract="IPersonService" name="BasicHttpBinding_IPersonService1" />
            </client>
    就是说,有多个终结点(多个endpoint),所以你必须要指定一个,你可以把代码写成这样:
    PersonServiceClient client = new PersonServiceClient("BasicHttpBinding_IPersonService");
    就行了。
    这些在我本地调试通过。
      

  10.   

    有用 完全正确,因为你web层应用的只是类库项目中的DLL,没有对于的app.Config配置信息,所以类库中任何调用配置文件的信息最好是调用web层的config信息。+1 有用的  在类库中添加服务引用  会生成一个app.config  把app.config的东西放到web.config就行了  
      

  11.   

    2  楼 和 17楼说的都对!把类库里面的app.config 里面的东西复制到web.config里面去就可以了!
      

  12.   

    复制过去是没问题。生成DLL时会生成一个.config文件,如果能动态查找就好了
      

  13.   

    我也遇到了这个问题
    不过我已经解决了
    是这样的
    1 首先配置web.config
    <bindings>
          <basicHttpBinding>
    --这个节点中,加入就是这一段
    <binding name="APISoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
    --这个节点中,加入就是这一段
    </basicHttpBinding>
        </bindings>然后<client>
    --这个节点中,加入就是这一段
    <endpoint address="http://mail.geely.com/apiws/services/API"
            binding="basicHttpBinding" bindingConfiguration="APISoapBinding"
            contract="CoremailXTAPI.API" name="APIPort" />
    --这个节点中,加入就是这一段
    </client>当两端 配置加好后,实例化对象的时候,要这样
    //APIPort这个名字就是对应的endpoint 节点中的 name="APIPort" 
    APIClient API=new APIClient("APIPort")这样就完成了~当然记得把web里的bin下的dll更新一下(这里不会多出dll,还是未添加web引用钱的那些dll)
      

  14.   

    有用 完全正确,因为你web层应用的只是类库项目中的DLL,没有对于的app.Config配置信息,所以类库中任何调用配置文件的信息最好是调用web层的config信息。+1 有用的  在类库中添加服务引用  会生成一个app.config  把app.config的东西放到web.config就行了  
    你说的是对的,正确答案!