Receive error: Cannot find declaration element 'ActivityId'

Receive error: Cannot find declaration element 'ActivityId'

这个错误超出了我的技能范围,所以如果我做出了一些错误的假设,我深表歉意:

ActivityId 在从客户端向服务器发出 API 调用时分配,因此我假设我无法控制它的生成方式。

假设我无法控制 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\vsaba582\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\vsaba582\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\vsaba582\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'

    }
}

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

在 Web.Config 中禁用 ActivityTracing 就成功了。删除的话 Activity跟踪并将传播Activity设置为假:

<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>