首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.ServiceModel.Channels.MessageHeader错误

System.ServiceModel.Channels.MessageHeader错误
EN

Stack Overflow用户
提问于 2010-12-30 16:39:24
回答 1查看 2.5K关注 0票数 0

我试图让以下内容在我的机器上工作,但我得到了一个错误(无法创建抽象类或接口‘System.ServiceModel.Channels.MessageHeader’的实例)

代码语言:javascript
复制
using System;
using System.IO;
using System.Reflection;

namespace com.companyname.business
{
    /// <summary>
    /// Summary description for SessionCreateRQClient.
    /// </summary>
    class SessionCreateRQClient
    {
        /// <summary>
        /// The main entry point.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            try 
            {
                // Set user information, including security credentials and the IPCC.
                string username = "user";
                string password = "password";
                string ipcc = "IPCC";
                string domain = "DEFAULT";

                string temp = Environment.GetEnvironmentVariable("tmp");    // Get temp directory
                string PropsFileName = temp + "/session.properties";        // Define dir and file name
                DateTime dt = DateTime.UtcNow;
                string tstamp = dt.ToString("s") + "Z";

                //Create the message header and provide the conversation ID.
                MessageHeader msgHeader = new MessageHeader();
                msgHeader.ConversationId = "TestSession";       // Set the ConversationId

                From from = new From();
                PartyId fromPartyId = new PartyId();
                PartyId[] fromPartyIdArr = new PartyId[1];
                fromPartyId.Value = "WebServiceClient";
                fromPartyIdArr[0] = fromPartyId;
                from.PartyId = fromPartyIdArr;
                msgHeader.From = from;

                To to = new To();
                PartyId toPartyId = new PartyId();
                PartyId[] toPartyIdArr = new PartyId[1];
                toPartyId.Value = "WebServiceSupplier";
                toPartyIdArr[0] = toPartyId;
                to.PartyId = toPartyIdArr;
                msgHeader.To = to;

            //Add the value for eb:CPAId, which is the IPCC. 
            //Add the value for the action code of this Web service, SessionCreateRQ.

                msgHeader.CPAId = ipcc;
                msgHeader.Action = "SessionCreateRQ";
                Service service = new Service();
                service.Value = "SessionCreate";
                msgHeader.Service = service;

                MessageData msgData = new MessageData();
                msgData.MessageId = "mid:20001209-133003-2333@clientofsabre.com1";
                msgData.Timestamp = tstamp;
                msgHeader.MessageData = msgData;

                Security security = new Security();
                SecurityUsernameToken securityUserToken = new SecurityUsernameToken();
                securityUserToken.Username = username;
                securityUserToken.Password = password;
                securityUserToken.Organization = ipcc;
                securityUserToken.Domain = domain;
                security.UsernameToken = securityUserToken;


                SessionCreateRQ req = new SessionCreateRQ();
                SessionCreateRQPOS pos = new SessionCreateRQPOS();
                SessionCreateRQPOSSource source = new SessionCreateRQPOSSource();
                source.PseudoCityCode = ipcc;
                pos.Source = source;
                req.POS = pos;

                SessionCreateRQService serviceObj = new SessionCreateRQService();
                serviceObj.MessageHeaderValue = msgHeader;
                serviceObj.SecurityValue = security;


                SessionCreateRS resp = serviceObj.SessionCreateRQ(req); // Send the request

                if (resp.Errors != null && resp.Errors.Error != null)
                {
                    Console.WriteLine("Error : " + resp.Errors.Error.ErrorInfo.Message);
                }

                else
                {
                    msgHeader = serviceObj.MessageHeaderValue;
                    security = serviceObj.SecurityValue;

                    Console.WriteLine("**********************************************");
                    Console.WriteLine("Response of SessionCreateRQ service");
                    Console.WriteLine("BinarySecurityToken returned : " + security.BinarySecurityToken);
                    Console.WriteLine("**********************************************");
                    string ConvIdLine = "convid="+msgHeader.ConversationId; // ConversationId to a string
                    string TokenLine = "securitytoken="+security.BinarySecurityToken;   // BinarySecurityToken to a string
                    string ipccLine = "ipcc="+ipcc; // IPCC to a string

                    File.Delete(PropsFileName);     // Clean up
                    TextWriter tw = new StreamWriter(PropsFileName);    // Create & open the file
                    tw.WriteLine(DateTime.Now);     // Write the date for reference
                    tw.WriteLine(TokenLine);        // Write the BinarySecurityToken
                    tw.WriteLine(ConvIdLine);       // Write the ConversationId
                    tw.WriteLine(ipccLine);     // Write the IPCC
                    tw.Close();

                    //Console.Read();
                }

            }
            catch(Exception e)
            {
                Console.WriteLine("Exception Message : " + e.Message );
                Console.WriteLine("Exception Stack Trace : " + e.StackTrace);
                Console.Read();
            }


        }
    }
}

我添加了引用System.ServiceModel和行:

代码语言:javascript
复制
using System.ServiceModel;
using System.ServiceModel.Channels;

但是当我试图编译的时候,我仍然会发现这个错误--

Cannot create an instance of the abstract class or interface 'System.ServiceModel.Channels.MessageHeader'

我使用的是2008版本9.0.21022.8RTM微软.NET框架版本3.5 SP1专业版

我还要补充另一项参考资料吗?或者是要搬过来的dll?

我想知道上面的代码仅仅是为Framework2.0编写的吗?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2010-12-30 16:48:59

错误消息是正确的,您不能创建该类的实例,它被声明为抽象。

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheader.aspx

查看静态方法MessageHeader.CreateHeader是否适合您。注意,有几个过载,所以选择最好的一个给你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4564417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档