Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Exchange 2010推送订阅WCF SOAP_C#_Wcf_Soap_Exchange Server_Ews Managed Api - Fatal编程技术网

C# Exchange 2010推送订阅WCF SOAP

C# Exchange 2010推送订阅WCF SOAP,c#,wcf,soap,exchange-server,ews-managed-api,C#,Wcf,Soap,Exchange Server,Ews Managed Api,我正在尝试使用Exchange 2010的PushSubscription功能。到目前为止,我已经获得了在Exchange 2010上安装推送的代码: ExchangeService esService = new ExchangeService(); esService.Credentials = new WebCredentials("user", "pass", "domain"); esService.Url = new Uri("https://exchange-box-2010/ew

我正在尝试使用Exchange 2010的PushSubscription功能。到目前为止,我已经获得了在Exchange 2010上安装推送的代码:

ExchangeService esService = new ExchangeService();
esService.Credentials = new WebCredentials("user", "pass", "domain");
esService.Url = new Uri("https://exchange-box-2010/ews/exchange.asmx");

PushSubscription ps = esService.SubscribeToPushNotificationsOnAllFolders(new Uri("http://192.168.1.102:8080/FinWorkFlow"), 1, null, EventType.NewMail, EventType.Copied);
我还有一个WCF服务,它在运行时使用tcp跟踪实用程序从8080重定向到80。跟踪表明Exchange向发送了请求,并且从我的WCF服务发送了良好的响应。但是,SendNotification方法的SendNotificationResponseType参数始终为空:

SendNotificationResultType INotificationServiceBinding.SendNotification(SendNotificationResponseType request)
        {
            if(request != null && request.ResponseMessages != null)
            {
                foreach(ResponseMessageType messsage in request.ResponseMessages.Items)
                {
                    if(messsage.ResponseCode != ResponseCodeType.NoError)
                    {
                        return CreateNotificationResult(SubscriptionStatusType.Unsubscribe);
                    }

                    SendNotificationResponseMessageType mtNotificationMessage = (SendNotificationResponseMessageType)messsage;
                    NotificationType ntNotification = mtNotificationMessage.Notification;
                    string strSubscriptionId = ntNotification.SubscriptionId;

                    for(int i = 0; i < ntNotification.Items.Length; i++)
                    {
                        if(ntNotification.ItemsElementName[i].ToString() == "NewMailEvent")
                        {
                            BaseObjectChangedEventType bocet = (BaseObjectChangedEventType)ntNotification.Items[i];
                        }
                    }
                }
            }

            return CreateNotificationResult(SubscriptionStatusType.OK);
        }
SendNotificationResultType INotificationServiceBinding.SendNotification(SendNotificationResponseType请求)
{
if(request!=null&&request.ResponseMessages!=null)
{
foreach(请求中的ResponseMessageType Message.ResponseMessages.Items)
{
if(Message.ResponseCode!=ResponseCodeType.NoError)
{
返回CreateNotificationResult(SubscriptionStatusType.Unsubscribe);
}
SendNotificationResponseMessageType mtNotificationMessage=(SendNotificationResponseMessageType)消息;
NotificationType ntNotification=mtNotificationMessage.Notification;
字符串strSubscriptionId=ntNotification.SubscriptionId;
对于(int i=0;i
接口定义为:

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Web.Services.WebServiceBindingAttribute(Name = "NotificationServiceBinding", Namespace = "http://schemas.microsoft.com/exchange/services/2006/messages")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ServiceConfiguration))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DirectoryEntryType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TargetFolderIdType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RecurrenceRangeBaseType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RecurrencePatternBaseType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(AttachmentType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BasePermissionType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseItemIdType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseEmailAddressType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseFolderIdType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseResponseMessageType))]
[ServiceContract(Namespace = "http://schemas.microsoft.com/exchange/services/2006/messages", ConfigurationName = "Microsoft.Exchange.Notifications.INotificationServicePortType")]
public interface INotificationServiceBinding
{

    /// <remarks/>
    [OperationContract(Action = "*", ReplyAction = "*")]
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.microsoft.com/exchange/services/2006/messages")]
    SendNotificationResultType SendNotification([System.Xml.Serialization.XmlElementAttribute("SendNotification", Namespace = "http://schemas.microsoft.com/exchange/services/2006/messages")] SendNotificationResponseType SendNotification1);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“wsdl”,“2.0.50727.42”)]
[System.Web.Services.WebServiceBindingAttribute(Name=“NotificationServiceBinding”,命名空间=”http://schemas.microsoft.com/exchange/services/2006/messages")]
[System.Xml.Serialization.xmlcludeAttribute(typeof(ServiceConfiguration))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(DirectoryEntryType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(targetFolderId类型))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RecurrenceRangeBaseType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RecurrencePatternBaseType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(AttachmentType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(BasePermissionType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(BaseItemIdType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(BaseEmailAddressType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(BaseFolderIdType))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(BaseFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BaseResponseMessageType))]
[ServiceContract(命名空间=”http://schemas.microsoft.com/exchange/services/2006/messages,ConfigurationName=“Microsoft.Exchange.Notifications.INotificationServicePortType”)]
公共接口INotificationServiceBinding
{
/// 
[运营合同(Action=“*”,ReplyAction=“*”)]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(“http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification,Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[返回:System.Xml.Serialization.XmlElementAttribute(命名空间=”http://schemas.microsoft.com/exchange/services/2006/messages")]
SendNotificationResultType SendNotification([System.Xml.Serialization.XmlElementAttribute(“SendNotification”,命名空间=”http://schemas.microsoft.com/exchange/services/2006/messages“”]SendNotificationResponseType SendNotification1);
}
来自Exchange的典型请求是:

POST /FinWorkFlow HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
SOAPAction: http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification
Host: 192.168.1.102:8080
Content-Length: 1486
Connection: Close

<?xml version="1.0" encoding="utf-8"?><soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"><soap11:Header><RequestServerVersion xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" Version="Exchange2010" /></soap11:Header><soap11:Body><m:SendNotification xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"><m:ResponseMessages><m:SendNotificationResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:Notification><t:SubscriptionId>EgBiZnQtbWVybGluLnJibS5sYW4QAAAAz4lScRmxbEaLeCfsAFRDmEswGeTtJs0I</t:SubscriptionId><t:PreviousWatermark>AQAAAOUSjqlc3mdHh1LhIiuqSBc1UCgAAAAAAAA=</t:PreviousWatermark><t:MoreEvents>false</t:MoreEvents><t:NewMailEvent><t:Watermark>AQAAAOUSjqlc3mdHh1LhIiuqSBc8UCgAAAAAAAE=</t:Watermark><t:TimeStamp>2010-09-20T15:16:28Z</t:TimeStamp><t:ItemId Id="AAMkAGVmOWI3OGE5LWJmMjEtNDU4Mi1hY2JlLTdhYzZmMGQ2N2Q4ZABGAAAAAACd5Nq062e3ToqPr4+g8e/UBwDjUS8vlMohRaUyr3p641BAACy83CEfAABwOzEV48hOQJYkk18qYDCqAAAAnG3SAAA=" ChangeKey="CQAAAA==" /><t:ParentFolderId Id="AAMkAGVmOWI3OGE5LWJmMjEtNDU4Mi1hY2JlLTdhYzZmMGQ2N2Q4ZAAuAAAAAACd5Nq062e3ToqPr4+g8e/UAQDjUS8vlMohRaUyr3p641BAACy83CEfAAA=" ChangeKey="AQAAAA==" /></t:NewMailEvent></m:Notification></m:SendNotificationResponseMessage></m:ResponseMessages></m:SendNotification></soap11:Body></soap11:Envelope>
POST/FinWorkFlow HTTP/1.1
内容类型:text/xml;字符集=utf-8
接受:text/xml
SOAPAction:http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification
主持人:192.168.1.102:8080
内容长度:1486
连接:关闭
NOERROREGBIZNQTBWVYBGLULNJIBS5SYW4QAAAAZ4LSCRMXBEALECFSAFRDMESWGETTJS0IAQAAOUSJQLC3MDHH1LIUQSBC1UCGAAAAAAA=FALSAQAAAOUSJQLC3MDHH1LIUQSBC8UCGAAAAE=2010-09-20T15:16:28Z

有人能解释一下为什么SOAP请求的主体没有被提取并放入SendNotificationResponseType变量中吗?

终于找到了答案


事实证明,我使用了wsdl工具来构建接口——应该使用svcutil。这构建了一个具有正确方法属性的接口。

此机制是否支持新邮件到达邮箱时的通知?我是否可以注册新邮件事件-一次,并在邮件到达设备时立即接收邮件,而无需每隔几分钟轮询并向服务器发送请求。。?我希望能够尽快处理新邮件。