【问题标题】:Invalid operation Exception while instantiating object of asmx web service实例化 asmx Web 服务的对象时出现无效操作异常
【发布时间】:2013-07-29 16:08:17
【问题描述】:

我正在尝试将 .asmx Web 服务合并到我的应用程序中。

为此,我 1.创建了一个类库项目。 2. 使用给定的 wsdl 添加服务引用 3. app.Config 自动创建。 app.config 是

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="UploadWebServiceSoap" 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="UploadWebServiceSoap12">
                <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" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
            binding="basicHttpBinding" bindingConfiguration="UploadWebServiceSoap"
            contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap" />
        <endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
            binding="customBinding" bindingConfiguration="UploadWebServiceSoap12"
            contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap12" />
    </client>
</system.serviceModel>

完成所有设置后,我尝试在我的函数中调用 web-service 中的方法。

  UploadWebServiceSoapClient dpcClient = new UploadWebServiceSoapClient();

这是出错的地方

Could not find default endpoint element that references contract 'ServiceReference1.UploadWebServiceSoap' in the ServiceModel client configuration     section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

谁能告诉我为什么会出现这个错误。另外,我了解创建 basicHttpBinding 的绑定,但是创建了相同的端点和端点

【问题讨论】:

    标签: c# .net asp.net-mvc-3 web-services


    【解决方案1】:

    看起来好像您已多次创建服务引用。首先,您创建了 ServiceReference1,然后创建了 DPCServiceReference。您应该更改端点配置:

    contract="ServiceReference1.UploadWebServiceSoap"
    

    contract="DPCServiceReference.UploadWebServiceSoap"
    

    您有 2 行出现此错误。

    如果这无济于事,请尝试使用 Soap12 删除 customBinding 和端点。

    【讨论】:

    • @Neha 您到底尝试了什么,得到了什么? UploadWebServiceSoapClient 是否实现了 DPCServiceReference.UploadWebServiceSoap?
    • 我将合同从 contract="ServiceReference1.UploadWebServiceSoap" 更改为 contract="DPCServiceReference.UploadWebServiceSoap" 并且我从我的应用配置中删除了 customBinding。但我仍然得到同样的错误
    • @Neha 您是否在托管 mvc 应用程序的同一项目中添加服务引用?如果不确保实际的web.config有这个配置,而不是不同项目中的app.config。
    • 非常感谢。我从早上就开始了。我只是想了解为什么我在主机 mvc 应用程序的 Web 配置中添加了所有信息,而不仅仅是在我添加服务参考的不同项目的应用程序配置中添加了我的服务参考
    • @Neha mvc 应用程序的 web.config 是唯一使用的,其他项目的 app.config 不会复制到输出目录,直接忽略。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多