Script component with WCF Invalid contract attribu

2019-07-11 07:09发布

问题:

I'm trying to configure a script component with a service reference to my WSDL file inside this boiler plate method.

public override void CreateNewOutputRows()
    {
       //create instance of service client 

    }

However I'm running into problems with the configuration file app.config which is complaining about an invalid contract attribute contract="ServiceReference1.IClientService1 All attempts to change this manually have failed. Similar posts suggest using a fully qualified name Service.MyService but I'm not having any success so far. Is there a way to specify the binding programmatically?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IClientService1">
                    <security mode="Transport" />
                </binding>
                <binding name="BasicHttpBinding_IClientService11" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://server/services/ClientService1.svc/soap"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientService1"
                contract="ServiceReference1.IClientService1" name="BasicHttpBinding_IClientService1" />
        </client>
    </system.serviceModel>
</configuration>

Stub code looks like following

 public override void CreateNewOutputRows()
    {
        string endpoint = "https://server/services/ClientService1.svc";
        ClientService1Client client = new ClientService1Client(endpoint);
        client.ClientCredentials.UserName.UserName = "";
        client.ClientCredentials.UserName.Password = "";
        Output0Buffer.name = client.GetActiveClients()[1].name.ToString();
    }

回答1:

I believe your issue may be due to having /soap in your endpoint address

<endpoint address="https://server/services/ClientService1.svc/soap"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientService1"
                contract="ServiceReference1.IClientService1" name="BasicHttpBinding_IClientService1" />

I think it should just be:

address="https://server/services/ClientService1.svc"

As for creating the binding programmatically this should work or get you started:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress address = new EndpointAddress("https://server/services/ClientService1.svc");
ClientService1Client client = new ClientService1Client(binding, address);


标签: c# wcf ssis