Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从事件接收器调用web服务_C#_Webservice Client - Fatal编程技术网

C# 从事件接收器调用web服务

C# 从事件接收器调用web服务,c#,webservice-client,C#,Webservice Client,我正在使用C#构建事件接收器以监视特定的exchange server收件箱。 我的实现基于以下示例: 我尝试向web服务发送一些特定信息,而不是示例中描述的功能。 我使用visual studio将服务引用添加到我的类库中,并使用以下代码调用web服务中的单个方法: public void OnSave(IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags) { try { Message iM

我正在使用C#构建事件接收器以监视特定的exchange server收件箱。 我的实现基于以下示例:

我尝试向web服务发送一些特定信息,而不是示例中描述的功能。 我使用visual studio将服务引用添加到我的类库中,并使用以下代码调用web服务中的单个方法:

public void OnSave(IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags)
{
    try
    {
        Message iMessage = new MessageClass();
        iMessage.DataSource.Open(bstrURLItem, null,
               ADODB.ConnectModeEnum.adModeRead,
               ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
               ADODB.RecordOpenOptionsEnum.adOpenSource, "", "");

        string sub= iMessage.Subject;

        string body = iMessage.HTMLBody;

        MyWSSoapClient wsc = new MyWSSoapClient();
        wsc.SingleMethodinWS(sub, body); 
    }
    catch (Exception ex)
    {
    }
}
构建COM组件并将事件接收器添加到收件箱并对其进行测试后,我发现错误:

Could not find default endpoint element that references contract 'MyWS.MyWSSoap' 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.
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1..ctor()
   at ReplyParserEventSink.AnswerQuestionWS.AnswerQuestionWSSoapClient..ctor()
   at ReplyParserEventSink.AsyncParser.OnSave(IExStoreEventInfo pEventInfo, String bstrURLItem, Int32 lFlags)
编辑: 这是我在应用程序配置中找到的

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyWSSoap" 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>
<endpoint address="http://127.0.0.1/MyProject/WebService/MyWS.asmx"
                binding="basicHttpBinding" bindingConfiguration="MyWSSoap"
                contract="MyWS.MyWSSoap" name="MyWSSoap" />
</system.serviceModel>


@亚历山大:我试过你说的,但我也犯了同样的错误。谢谢

这当然是VS2010。问题在于
app.config
中的自动生成代码

检查你的
app.config
。此文件包含绑定和终结点的所有防御。只需首先检查端点,检查端点是否已被描述,绑定是否也已定义

尝试之后:

MyWSSoapClient wsc = new MyWSSoapClient( "<endpointConfigurationName>" );

这当然是VS2010。问题在于
app.config
中的自动生成代码

检查你的
app.config
。此文件包含绑定和终结点的所有防御。只需首先检查端点,检查端点是否已被描述,绑定是否也已定义

尝试之后:

MyWSSoapClient wsc = new MyWSSoapClient( "<endpointConfigurationName>" );

我在回答我自己的问题,因为我已经发现并解决了这个问题

问题是类库的app.config文件中的信息没有进入com组件,因此出现了错误

我通过以下示例在外部文本文件中设置代码中的所有参数值来修复此问题:


谢谢大家的建议。

我在回答我自己的问题,因为我已经发现并解决了这个问题

问题是类库的app.config文件中的信息没有进入com组件,因此出现了错误

我通过以下示例在外部文本文件中设置代码中的所有参数值来修复此问题:

谢谢大家的建议