user278618
user278618

Reputation: 20222

why OperationContext.Current is null?

At the client I need to call this method:

<OperationContract()> <WebMethod()> _
Public Function NotifierSignIn(ByRef url As String, ByVal login As String, ByVal password As String, ByVal sessionGuid As String, ByVal customerGuid As String) As String
    Dim ret = String.Empty
    Return ret
End Function

I 'm trying to call it as:

//sessionGuid is empty
string url = string.Empty;
string result = ws.NotifierSignIn(ref url, txtLogin.Text, txtPassword.Password, sessionGuid, txtCustomerGuid.Text);

First what is executed is method at wcf service (.net 3.5):

Public Sub New()
    System.Net.ServicePointManager.ServerCertificateValidationCallback = _
        New System.Net.Security.RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
    _errMsgs = ErrorMessages.GetInstance()

    _authHandlerId = SoapHeaderHelper(Of Integer).GetInputHeader("HandlerId")

End Sub

And I get error at

public object GetInputHeader(string name)
{
    return GetHeader(name, OperationContext.Current.IncomingMessageHeaders);
}

because OperationContext.Current is null.

My service is wcf service because I user

<%@ServiceHost Language="VB" Service="MyWS.Service1" %>

What is interesting I have nothing in fiddler.

How can I fix it?

EDIT Following Marc suggestion (thanks Mark) I've moved initialization of field to propety. But there is still a problem. It enters to my webmethod , but in it there is next exception, because OperationContext.Current is still null. To be clear : at the first line of my webmethod I have : Dim context=OperationContext.Current and unfortunately it is null :/

So, there must be another factor.

Here is my app.config at the client:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyITNotifier.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    </sectionGroup>
  </configSections>

  <connectionStrings />

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Soap" 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://localhost:50002/MyIT.asmx" binding="basicHttpBinding"
        bindingConfiguration="Service1Soap" contract="ServiceReference1.Service1Soap"
        name="Service1Soap1" />
    </client>

  </system.serviceModel>

  <userSettings>
    <MyITNotifier.Properties.Settings>
      <setting name="UseAnimation" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="SoundFilePath" serializeAs="String">
        <value/>
      </setting>
      <setting name="UseCustomSound" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="PlaySound" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="HandlerId" serializeAs="String">
        <value>1</value>
      </setting>
      <setting name="SessionGuid" serializeAs="String">
        <value/>
      </setting>
      <setting name="MyItUrl" serializeAs="String">
        <value/>
      </setting>
      <setting name="Interval" serializeAs="String">
        <value>2</value>
      </setting>
      <setting name="RememberUser" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="CustomerGuid" serializeAs="String">
        <value/>
      </setting>
    </MyITNotifier.Properties.Settings>
  </userSettings>
<startup><supportedRuntime version="v2.0.50727"/></startup>
</configuration>

Upvotes: 2

Views: 4735

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87218

In the client configuration the endpoint address is listed as http://localhost:50002/MyIT.asmx. ASMX services aren't WCF services, so if you try to access any WCF service property while running in an ASMX service (the WebMethod() declaration in your operation), then they'll be null. Try regenerating the client by pointing the tool (svcutil / Add Service Reference) to the .svc file, not the .asmx one.

Upvotes: 1

Related Questions