Windows Server TechCenter > Windows Server Forums > Windows PowerShell > power shell : System.ServiceModel.OperationContextScope : cannot creat constructor
Ask a questionAsk a question
 

Questionpower shell : System.ServiceModel.OperationContextScope : cannot creat constructor

  • Tuesday, October 13, 2009 2:55 PMkmkiran Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
     in  the power shell it is giving the error for System.ServiceModel.OperationContextScope unbale to create object of it. I am able to create the $proxy
     
    $d = New-Object System.ServiceModel.OperationContextScope($proxy.InnerChannel)

     Error:

    Constructor not Found. Cannot Find the Appropriate Constructor for type System.ServiceModel.OperationContextScope


    Sample C# CODE:

    // Call to Login Service and receving an authentication token as the result
    // on sucessful authentication.
    // Declaring an instance of WebService Client SampleServiceClient
    wcfClient = new SampleServiceClient(new InstanceContext(this));
    try {
    // Creation of an object of type "OperationContextScope"
    // received an error in the below line while instantiation
    using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel))
     {
    // Creation of objevt of type HttpRequestMessageProperty
    HttpRequestMessageProperty request = new HttpRequestMessageProperty();
    request.Headers["Cookie"] = "LoginCert=" + _authToken;
    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = request;
    }
    Thanks,
     Kiran K
    • Changed Typekmkiran Friday, October 23, 2009 8:14 AM
    •  

All Replies

  • Thursday, October 15, 2009 12:53 AMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You should provide the code on how you create $proxy.  We need to determine if the right type of object is being passed.

    Please don't open a new thread, you should have continued adding to your last post.
  • Friday, October 23, 2009 8:22 AMkmkiran Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am following the process of creating proxy from the following link

    http://cglessner.blogspot.com/2008/12/call-wcf-services-with-powershell.html/



    Power shell Code for Creating the $proxy:

    $wsdl = Get-WsdlImporter -wsdlUrl "http://myservice/mex"

    $proxyTypes = Get-WcfProxy -wsdlImporter $wsdl

    $address = New-Object System.ServiceModel.EndpointAddress("http://myservice")


    $binding = new-object System.ServiceModel.BasicHttpBinding
    #system.

    $proxy = New-Object $proxyTypes -ArgumentList $binding, $address

    $d = New-Object System.ServiceModel.OperationContextScope($proxy.InnerChannel)



    Error:

    Cannot convert argument "0", with value: "ISetService", for ".ctor" to type "System.ServiceModel.IContextChannel": "Cannot convert "ISetService" to "System.ServiceModel.IContextChannel"."
    At :line:45 char:17
    + $pdc = new-object <<<<  System.ServiceModel.OperationContextScope($proxyLRC.InnerChannel)


    The C# code works fine but when I try to implement it using the power Shell then it fails.

    this may help u.

    Kiran K

  • Friday, October 23, 2009 12:03 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks.  It will take me a while to go through all of this.  I downloaded his WCF demo, but the contents of the zip aren't compiling as-is for me with Visual Studio 2008 C# Express.
  • Friday, October 30, 2009 4:54 AMkmkiran Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is there any other way by which I can achieve this. without using the operation context. So it will be easy for power shell to get.

    Is this limitation of the power shell...



    Sample C# CODE:

    // Call to Login Service and receving an authentication token as the result
    // on sucessful authentication.
    // Declaring an instance of WebService Client SampleServiceClient
    wcfClient = new SampleServiceClient(new InstanceContext(this));
    try {
    // Creation of an object of type "OperationContextScope"
    // received an error in the below line while instantiation
    using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel))
     {
    // Creation of objevt of type HttpRequestMessageProperty
    HttpRequestMessageProperty request = new HttpRequestMessageProperty();
    request.Headers["Cookie"] = "LoginCert=" + _authToken;
    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = request;
    }
  • Tuesday, November 03, 2009 2:10 PMkmkiran Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I followed the steps mentioned in the blog below but I get the below Error

    http://keithhill.spaces.live.com/Blog/cns!5A8D2641E0963A97!645.entry?sa=80027505

    Power Shell Code:


    cd 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin'

    .\SvcUtil.exe http://myservice.svc

     cd 'C:\WINDOWS\Microsoft.NET\Framework\v3.5'

     .\csc /t:library LaborRateCardSetService.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"


    csc /t:library CalculatorService.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"

    [Reflection.Assembly]::LoadWithPartialName("System.ServiceModel")

    [Reflection.Assembly]::LoadFrom("$pwd\myservice.dll")

    $wsHttpBinding = new-object System.ServiceModel.BasicHttpBinding

    $endpoint = new-object System.ServiceModel.EndpointAddress ("http://myservice.svc ")

    $calcService = new-object myserviceServiceClient($wsHttpBinding, $endpoint)

    $innerChannel =   $calcService.InnerChannel
    $innerChannel | gm
    $pdc = new-object System.ServiceModel.OperationContextScope($innerChannel)

    Error:

    New-Object : Cannot find an overload for "OperationContextScope" and the argume
    nt count: "1".
    At C:\DOCUME~1\local~1.KAK\LOCALS~1\Temp\db5437e9-b297-4e51-af01-caab00ec1201.p
    s1:26 char:18
    + $pdc = new-object <<<<  System.ServiceModel.OperationContextScope($innerChann
    el)
        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodExcept
       ion
        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
       Shell.Commands.NewObjectCommand


    Regards,
    Kiran K
  • Thursday, November 05, 2009 6:17 AMkmkiran Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    Please check the Configuration

    Windows                               :               Windows XP  SP3

    Power Shell Version            :               Windows PowerShell V2 CTP

    .net Frame work                   :               3.5 SP1