当前在线人数9973
首页 - 分类讨论区 - 电脑网络 - 窗口里的风景版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Re: add web service
[同主题阅读] [版面: 窗口里的风景] [作者:AlbertLin] , 2014年01月29日12:58:26
AlbertLin
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: AlbertLin (Albert Lin), 信区: DotNet
标  题: Re: add web service
发信站: BBS 未名空间站 (Wed Jan 29 12:58:26 2014, 美东)

呵呵, 他们sample code都不给,你还指望他们给你新api? 你们知道什么是 primary
signature吗? 我现在的error是the primary signature must be encrypted。

我现在的function可以送request, 用fiddler我也可以看到response, 可是用他们的
proxy得到reponse就出错。我想是不是我的setting不对。


            EndpointAddress ea = new EndpointAddress("https://misapi.ercot.
com/2007-08/Nodal/eEDS/EWS/");
            System.ServiceModel.Channels.CustomBinding custombinding = new
System.ServiceModel.Channels.CustomBinding();
            
            System.ServiceModel.Channels.AsymmetricSecurityBindingElement
sbe = System.ServiceModel.Channels.AsymmetricSecurityBindingElement.
CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.
WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPol
icy11BasicSecurityProfile10);
            sbe.SecurityHeaderLayout = System.ServiceModel.Channels.
SecurityHeaderLayout.Strict;
            sbe.IncludeTimestamp = false;
            sbe.SetKeyDerivation(false);
            sbe.LocalClientSettings.MaxClockSkew = new TimeSpan (0,3,0);
            sbe.LocalClientSettings.ReplayWindow = new TimeSpan(0, 2, 0);
            sbe.LocalClientSettings.ReplayCacheSize = 10000;
            sbe.LocalServiceSettings.MaxClockSkew = new TimeSpan(0, 3, 0);
            sbe.AllowSerializedSigningTokenOnReply = true;
            sbe.RequireSignatureConfirmation = false;
            
            System.ServiceModel.Channels.HttpsTransportBindingElement
transport = new System.ServiceModel.Channels.HttpsTransportBindingElement();

            custombinding.Elements.Add(sbe);
            custombinding.Elements.Add(new System.ServiceModel.Channels.
TextMessageEncodingBindingElement(System.ServiceModel.Channels.
MessageVersion.Soap11, System.Text.Encoding.UTF8));
            custombinding.Elements.Add(transport);


            OperationsClient client = new OperationsClient(custombinding,ea);
           
            //client certificate
            System.Security.Cryptography.X509Certificates.X509Certificate2
ercotcert = new System.Security.Cryptography.X509Certificates.
X509Certificate2("C:\ESettlement\ESettlementConsole\albertqse2014.pfx","xxx"
);
            client.ClientCredentials.ClientCertificate.Certificate =
ercotcert;
           
            //server certificate
            System.Security.Cryptography.X509Certificates.X509Certificate2
ercotservicecert = new System.Security.Cryptography.X509Certificates.
X509Certificate2("C:\ESettlement\ESettlementConsole\misapi.ercot.com public
key.cer");
            client.ClientCredentials.ServiceCertificate.DefaultCertificate =
ercotservicecert;
            client.Open();
            
           
            DateTime dt = DateTime.Now.AddDays(-1);
            RequestMessage RM = new RequestMessage();
            RequestType rt = new RequestType();
            HeaderType ht = new HeaderType();

            rt.StartTime = new DateTime(dt.Year,dt.Month,dt.Day,0,0,0,0);
            rt.StartTimeSpecified = true;
            rt.EndTime = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59,
999);
            rt.EndTimeSpecified = true;
            rt.Option = "11113";//Real Time Market Consolidated Operating
Day Extract
            rt.OperatingDate = DateTime.Now;
           
            ht.UserID = "API_xxxx";
            ht.Verb = HeaderTypeVerb.get;
            ht.Noun = "Reports";
            AttributedDateTime adt = new AttributedDateTime();
            EncodedString es = new EncodedString();
            Random r = new Random();
            es.Value = r.Next().ToString();
           
            adt.Value = DateTime.Now.ToString("s");
            
            ReplayDetectionType rdt = new ReplayDetectionType();
            rdt.Created = adt;
            rdt.Nonce = es;
            ht.ReplayDetection = rdt;

            ht.Revision = "001";
            ht.Source = "7800613002000";
            //ht.MessageID = "151451";
            RM.Header = ht;
            RM.Request = rt;

            XmlSerializer ser = new XmlSerializer(RM.GetType());
            StringWriter sw = new StringWriter();
            ser.Serialize(sw, RM);
            string xml = sw.ToString();
            try
            {
                ResponseMessage responsemessage = client.MarketInfo(RM);
            }
            catch (Exception ex)
            {
                //client.Close();
            }
--

※ 修改:·AlbertLin 於 Jan 29 12:59:14 2014 修改本文·[FROM: 66.]
※ 来源:·WWW 未名空间站 海外: mitbbs.com 中国: mitbbs.cn·[FROM: 66.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:

未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996