自定义SoapHeader php到C#

自定义SoapHeader php到C#,c#,php,soap,C#,Php,Soap,在C#中如何使用ServiceReference或WebReference实现这一点 class SoapAuthentificationHeader { /** @var string sPassword */ public $Password; /** @var string sLogin */ public $sLogin; /** @var string anotherCustomParam*/

在C#中如何使用ServiceReference或WebReference实现这一点

   class SoapAuthentificationHeader {
        /** @var string sPassword */
        public $Password;
        /** @var string sLogin */
        public $sLogin;
        /** @var string anotherCustomParam*/
        public $sVod;

        public function __construct($sLogin, $sPassword, $sVod) {
            $this->sPassword=$sPassword;
            $this->sLogin=$sLogin;
            $this->sVod=$sVod;
        }
    }

    $oSoap=new SoapClient('http://.[ my path ]...wsdl', array(
        'trace' => 1,
        'encoding' => 'UTF-8'
    ));

    try {
        $oSoap->__setSoapHeaders(array(new SoapHeader('urn:vod_soap', 'AuthenticationHeader', new SoapAuthentificationHeader('login', 'password', 'anotherCustomParam'))));     
$iCountVideo = $oSoap->countVideo();
    } catch (Exception $oException) {
        var_dump($oException);
    }
我尝试在我的通话中引用一个共享CookieContainer。但它不起作用:目前我有:

vod_soapService s = new vod_soapService();
            s.CookieContainer = new CookieContainer();

            s.ConnectionGroupName = "test";
             // this webmethod works it return me true 
            s.AuthenticationHeader("foo", "bar", "test");

            string test = s.countVideo();

在发送xml之前,必须手动插入soap头。要实现这一点,请阅读下面的链接

您还必须调整给定的解决方案以适合您的身份验证标头

您的“后序列化”实现应该如下所示:

case SoapMessageStage.AfterSerialize:
{
  // Get the SOAP body as a string, so we can manipulate...
  String soapBodyString = getXMLFromCache();

  String BodyString = "<soap:Body";
  int posStartBody = soapBodyString.IndexOf(BodyString);

  // Create the SOAP header Message 
  String soapEnvHeaderString = "<soap:Header><SoapAuthentificationHeader><sLogin>";
  String soapEnvHeaderString2 = "</sLogin><sPassword>";
  String soapEnvHeaderString3 = "</sPassword><sVod>";
  String soapEnvHeaderString4 = "</sVod></SoapAuthentificationHeader></soap:Header>";
  Stream appOutputStream = new MemoryStream();
  StreamWriter soapMessageWriter = new StreamWriter(appOutputStream);
  soapMessageWriter.Write(soapBodyString.Substring(0,posStartBody));
  soapMessageWriter.Write(soapEnvHeaderString);
  soapMessageWriter.Write("your login ");
  soapMessageWriter.Write(soapEnvHeaderString2);
  soapMessageWriter.Write("your password");
  soapMessageWriter.Write(soapEnvHeaderString3);
  soapMessageWriter.Write("your vod");
  soapMessageWriter.Write(soapEnvHeaderString4);
  soapMessageWriter.Write(soapBodyString.Substring(posStartBody));
  // write it all out.
  soapMessageWriter.Flush();
  appOutputStream.Flush();
  appOutputStream.Position = 0;
  StreamReader reader = new StreamReader(appOutputStream);
  StreamWriter writer = new StreamWriter(this.outputStream);
  writer.Write(reader.ReadToEnd());
  writer.Flush();
  appOutputStream.Close();
  this.outgoing = false;
  this.incoming = true;
  break;
}
case SoapMessageStage.AfterSerialize:
{
//将SOAP主体作为字符串获取,以便我们可以操纵。。。
字符串soapBodyString=getXMLFromCache();

String BodyString=“到目前为止,您尝试了什么?在这些对象的文档中找不到吗?如果找不到,您在哪里找到的?