收到错误:找不到声明元素'ActivityId'

时间:2015-04-22 19:01:14

标签: asp.net web-services soap wsdl wcf-security

这个错误超出了我的技能范围,所以如果我做出一些不正确的假设,我会道歉:

当从客户端到服务器进行API调用时,会分配ActivityId,所以我假设我无法控制它的生成方式。

假设我无法控制ActivitId的分配,这个问题是由我的IIS服务器和端点之间的握手引起的吗?

我可以在WSDL中进行修改以解决问题吗?

我已经发布了电话的跟踪事件和一些代码,请告诉我还有什么需要帮助解决问题。

以下是Trace Viewer中的结果,下面是我的代码:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>0</EventID>
<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2015-04-22T15:34:40.7214893Z" />
<Source Name="System.ServiceModel.MessageLogging" />
<Correlation ActivityID="{e7ac11ba-8f49-474d-8960-b9e3cf2da931}" />
<Execution ProcessName="iisexpress" ProcessID="17112" ThreadID="8" />
<Channel />
<Computer>JROBINSON6274</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<MessageLogTraceRecord Time="2015-04-22T11:34:40.7214893-04:00" Source="TransportSend" Type="System.ServiceModel.Dispatcher.OperationFormatter+OperationFormatterMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Addressing>
<Action>http://dpd.com/common/service/ShipmentService/3.2/storeOrders</Action>
<To>https://public-ws-stage.dpd.com/services/ShipmentService/V3_2/</To>
</Addressing>
<HttpRequest>
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<VsDebuggerCausalityData>uIDPoxiCfR3BJXhAguLEZnDHinsAAAAAG4onPL7yhk6XmHXeB+x5TTT6sGl21b5CuCON4NUt0YEACQAA</VsDebuggerCausalityData>
</WebHeaders>
</HttpRequest>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:authentication xmlns:h="http://dpd.com/common/service/types/Authentication/2.0" xmlns="http://dpd.com/common/service/types/Authentication/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<delisId xmlns="">######</delisId>
<authToken xmlns="">##################################</authToken>
<messageLanguage xmlns="">#####</messageLanguage>
</h:authentication>
<ActivityId CorrelationId="548239ec-6a8b-4628-8a8e-81141f15b3a0" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">e7ac11ba-8f49-474d-8960-b9e3cf2da931</ActivityId>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<storeOrders xmlns="http://dpd.com/common/service/types/ShipmentService/3.2">
<printOptions xmlns="">
<printerLanguage>PDF</printerLanguage>
<paperFormat>A6</paperFormat>
</printOptions>
<order xmlns="">
<generalShipmentData>
<identificationNumber>12345</identificationNumber>
<sendingDepot>0147</sendingDepot>
<product>CL</product>
<sender>
<name1>######</name1>
<street>#######</street>
<country>DE</country>
<zipCode>#####</zipCode>
<city>######</city>
<customerNumber>######</customerNumber>
</sender>
<recipient>
<name1>#######</name1>
<street>#########</street>
<country>####</country>
<zipCode>40599</zipCode>
<city>##########</city>
</recipient>
</generalShipmentData>
<parcels>
<customerReferenceNumber1>PDS124400203</customerReferenceNumber1>
</parcels>
<productAndServiceData>
<orderType>consignment</orderType>
</productAndServiceData>
</order>
</storeOrders>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>
</DataItem>
</TraceData>
<System.Diagnostics xmlns="http://schemas.microsoft.com/2004/08/System.Diagnostics">
<LogicalOperationStack></LogicalOperationStack>
<Timestamp>990348428488</Timestamp>
<Callstack>
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Diagnostics.TraceEventCache.get_Callstack()
at System.Diagnostics.XmlWriterTraceListener.WriteFooter(TraceEventCache eventCache)
at System.Diagnostics.XmlWriterTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
at System.Diagnostics.TraceSource.TraceData(TraceEventType eventType, Int32 id, Object data)
at System.ServiceModel.Diagnostics.MessageLogger.LogInternal(MessageLoggingSource source, Object data)
at System.ServiceModel.Diagnostics.MessageLogger.LogInternal(MessageLogTraceRecord record)
at System.ServiceModel.Diagnostics.MessageLogger.LogMessageImpl(Message& message, XmlReader reader, MessageLoggingSource source)
at System.ServiceModel.Diagnostics.MessageLogger.LogMessage(Message& message, XmlReader reader, MessageLoggingSource source)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message, Boolean shouldRecycleBuffer)
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at DPDWebServiceShipment.ShipmentService_3_2.storeOrders(storeOrdersRequest request)
at DPDWebServiceShipment.ShipmentService_3_2Client.DPDWebServiceShipment.ShipmentService_3_2.storeOrders(storeOrdersRequest request) in c:\Users\Jeffrey\AppData\Local\Temp\Temporary ASP.NET Files\vs\97aba582\bf0e7c3e\App_WebReferences.lgiqd1ag.0.cs:line 3842
at DPDWebServiceShipment.ShipmentService_3_2Client.storeOrders(authentication authentication, storeOrders storeOrders1) in c:\Users\Jeffrey\AppData\Local\Temp\Temporary ASP.NET Files\vs\97aba582\bf0e7c3e\App_WebReferences.lgiqd1ag.0.cs:line 3849
at DPDLabels.Button1_Click(Object sender, EventArgs e) in c:\PDS_NET\Site\DPDLabels.aspx.cs:line 98
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.dpdlabels_aspx.ProcessRequest(HttpContext context) in c:\Users\Jeffrey\AppData\Local\Temp\Temporary ASP.NET Files\vs\97aba582\bf0e7c3e\App_Web_e5verntf.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
</Callstack>
</System.Diagnostics>
</ApplicationData>
</E2ETraceEvent>

这是我的代码:

using DPDWebServiceLogin;
using DPDWebServiceShipment;

public partial class DPDLabels : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        LoginServiceClient objLogin = new LoginServiceClient();

        var objAuthToken = objLogin.getAuth("######", "######", "######");
        Label1.Text = objAuthToken.authToken.ToString();

        ShipmentService_3_2Client objShipment = new ShipmentService_3_2Client();

        var objAuth = new authentication { 
            delisId = "######",
            authToken = objAuthToken.authToken,
            messageLanguage = "#####",
        };

        var objPrinter = new printOptions {
            printerLanguage = printOptionsPrinterLanguage.PDF,
            paperFormat = printOptionsPaperFormat.A6,            
        };

        var objSenderAddress = new address {
            name1 = "IML GDN",
            street = "Nurnberger Straue 12",
            city = "Dusseldorf",
            country = "DE",
            zipCode = "40599",
            customerNumber = "03180008",
        };

        var objRecipientAddress = new address {
            name1 = "Nikolas Meyer",
            street = "Nurnberger Str 12",
            city = "Dusseldorf",
            country = "DE",
            zipCode = "40599",        
        };

        var objShipmentData = new generalShipmentData {
            identificationNumber = "12345",
            sendingDepot = "0147",
            product = generalShipmentDataProduct.CL,
            sender = objSenderAddress,            
            recipient = objRecipientAddress,                     
        };

        var objParcels = new parcel
        {
            customerReferenceNumber1 = "PDS124400203",
        };

        var objProductService = new productAndServiceData
        {
            orderType = productAndServiceDataOrderType.consignment,
        };

        var objShipmentServiceData = new shipmentServiceData
        {
            generalShipmentData = objShipmentData,
            parcels = new[] {objParcels},
            productAndServiceData = objProductService,
        };

        var objStoreOrder = new storeOrders
        {
            printOptions = objPrinter,
            order = new[] { objShipmentServiceData },
        };

        storeOrdersResponse objShipmentResponse = new storeOrdersResponse();
        **objShipmentResponse = objShipment.storeOrders(objAuth, objStoreOrder);** here is the line that produces the error: Cannot find the declaration of element 'ActivityId'

    }
}

1 个答案:

答案 0 :(得分:0)

希望这能帮助遇到错误的其他人:找不到声明元素'ActivityId'。该问题与在对Java Web Services进行API调用时打开的“活动跟踪”功能有关。

在Web.Config中禁用ActivityTracing就可以了。删除单词 ActivityTracing并将propagateActivity设置为false:

<sources>
  <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
    <listeners>
      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
        <filter type="" />
      </add>
      <add name="ServiceModelMessageLoggingListener">
        <filter type="" />
      </add>
    </listeners>
  </source>
  <source name="System.ServiceModel" switchValue="Verbose" propagateActivity="false">
    <listeners>
      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
        <filter type="" />
      </add>
      <add name="ServiceModelTraceListener">
        <filter type="" />
      </add>
    </listeners>
  </source>
</sources>