1

I am using C# to build an event sink to monitor a specific exchange server inbox. My implementation is based on this example: http://www.codeproject.com/KB/exchange/ManagedEventSinks.aspx?fid=382114&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26#xx0xx

Instead of the functionality described in the example i am trying to send some specific information to a web service. I use visual studio to add the service reference to my class library and the following code to call the single method in the web service:

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)
    {
    }
}

After i build the COM component and add the event sink to the inbox and test it i get the error:

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)

EDIT: This is what i found in the app config

<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>

@Alexander: I tried what you said but i get the same error. Thanks

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Constantin
  • 465
  • 4
  • 18

2 Answers2

1

This is of course VS2010. Thing is with autogenerated code in app.config.

Check your app.config. This file contains all defenitions for bindings and endpoints. Just check you endpoints 1st, check whether your endpoint is described, and binding is defined too.

After that try:

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

and see what would happen.

Also in <client> area you will find description of endpoints. Try to change binding to basicHttpBinding manually - that worked for me.

    <endpoint address="http://service.address.com"
        binding="basicHttpBinding" bindingConfiguration="yourService"
        contract="Domain.Serice" name="serviceName" />
0

I am answering my own question because i have found and fixed the problem

The problem was that the information form the app.config file of the class library was not getting into the com component and therefore the error.

I fixed it by setting all my parameter values in my code from an external text file by following the example at: Consume a SOAP web service without relying on the app.config

Thanks for the suggestions everyone.

Community
  • 1
  • 1
Constantin
  • 465
  • 4
  • 18