当我调用Web服务操作时,WCF使用DataContractSerializer将消息反序列化到代理类:为什么我不能这样做?
以下是ActLoginResponse.xml文件中的soap消息:
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:PlotiIntf" xmlns:ns2="urn:PlotiIntf-IPloti" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<ns2:ActLoginResponse>
<return>
<ResultCode>0</ResultCode>
<ResultMessage>Login et password correct.</ResultMessage>
<Acteur>
<Id>IMT_706</Id>
<Nom>IMA PROTECT</Nom>
<Prenom/>
<nbFI>0</nbFI>
<FonctionActeur>TS</FonctionActeur>
<Timeout>30</Timeout>
</Acteur>
<ZneGeoList xsi:nil="true"/>
</return>
</ns2:ActLoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
相应的ActLoginResponse类的WCF代理代码是:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="ActLoginResponse", WrapperNamespace="urn:PlotiIntf-IPloti", IsWrapped=true)]
public partial class ActLoginResponse {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public Ploti.PlotiClient.LoginResponseType @return;
public ActLoginResponse() {
}
public ActLoginResponse(Ploti.PlotiClient.LoginResponseType @return) {
this.@return = @return;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我需要将XML解析为ActLoginResponse类型的对象实例.
以下是我执行解析的方法:
ActLoginResponse body;
FileStream stream = new FileStream("Requests\\ActLoginResponse.xml", FileMode.Open);
XmlReader xmlReader = XmlReader.Create(stream); …Run Code Online (Sandbox Code Playgroud) 我已经成功地锁定了承诺,但我发现我的方式足够复杂:我想知道是否有更优雅的方式来做到这一点.
我使用Angular2,Typescript和signalR.
我有一个服务getIntervention,通过Id从服务器返回一个对象.
在调用之前getIntervention,我想检查客户端是否连接到服务器,在连接到服务器之前,我希望加载SignalR脚本.
所以我创建了第一个scriptLoadedPromise等待SignalR脚本加载的承诺.当scriptLoadedPromise解决了一个新的承诺connectionPromise将创建一个等待要建立连接.
何时connectionPromise 解决,请致电该服务getIntervention.
对于每一个承诺,我添加了一个名为回调scriptLoaded 和connectionDetected 该呼叫resolve().
这是我的代码:
public loadIntervention( numFI : number ) : Promise<Intervention>
{
let scriptLoadedPromise : Promise<Intervention> = new Promise( ( resolve, reject ) =>
{
// si le script est chargé alors la promesse est déjà tenue
if ( this.isScriptLoaded )
resolve();
else
this.scriptLoaded = ( () => { resolve(); } ) ;
}).then
( …Run Code Online (Sandbox Code Playgroud) 我不明白为什么这两个运营商存在.在布尔比较的情况下,==和===似乎都有效,但是在枚举比较的情况下,只有'=='有效:
<div class="interventionGroup">
<div class="interventionGroupHeader transition_1s" (click)="onClickHeader()">
{{GroupName}}
<div *ngIf="expanded == true" class="expand-icon"><i class="material-icons">expand_less</i></div> <!-- WORKS -->
<div *ngIf="expanded === false" class="expand-icon"><i class="material-icons expand-icon">expand_more</i></div> <!-- WORKS -->
</div>
<button *ngIf="GroupType == GroupTypeEnum.mesInterventions">dfdsfsd</button> <!-- WORKS -->
<div style="list-style-type:none" *ngIf="expanded === true">
<div *ngFor="let intervention of interventions"
(click)="onClick(intervention)">
<intervention-button [intervention]="intervention"></intervention-button>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我模拟了一个接口,通过 Newtonsoft JsonConvert.SerializeObject 的测试代码将对象从该接口序列化。
序列化程序抛出异常并显示以下错误:
Newtonsoft.Json.JsonSerializationException:检测到类型为“Castle.Proxies.IActionProxy”的属性“Object”的自引用循环。路径“模拟”。
Newtonsoft 尝试序列化代理对象 IActionProxy,该对象具有在该序列化对象上循环的属性 Mock。
奇怪地改变序列化器选项
ReferenceLoopHandling = ReferenceLoopHandling.Serialize ( ot Ignore)
PreserveReferencesHandling = PreserveReferencesHandling.All
Run Code Online (Sandbox Code Playgroud)
..不解决问题,序列化变成无限
感谢您对此问题的帮助,我很乐意在这种情况下使用 Moq
更新:这是产生异常的示例代码:
Mock<IAction> _actionMock = new Mock<IAction>().SetupAllProperties();
Newtonsoft.Json.JsonConvert.SerializeObject( _actionMock.Object ); // JsonSerializationException (this line is in a method which i'm not responsible of )
// IAction is any interface with some properties
Run Code Online (Sandbox Code Playgroud)
我们必须考虑序列化(SerializeObject)是由我无权访问的库中的测试代码调用的。
我第一次使用部署管道将 Python 函数应用部署到 Azure:
https://docs.microsoft.com/bs-latn-ba/azure/azure-functions/functions-how-to-azure-devops
该包使用 Kudu Zip 部署部署到 Azure。
我的 http 触发函数在本地运行得很好(在 Windows 上),但我在 Azure 上有 500 个内部错误,因为它没有找到模块requests。
异常:ModuleNotFoundError:没有名为“请求”的模块
__init__.py 的导入:
import logging, requests, os
import azure.functions as func
Run Code Online (Sandbox Code Playgroud)
如果我删除“请求”依赖项,则该函数可在 Azure 上运行(状态 200)。
requests 库由requirement.txt导入,并由构建管道复制到.venv36/lib/site-packages/requests。
所以我想知道包中内置的虚拟环境.venv36是否被Azure中部署的函数使用。没有关于如何在 Azure 中激活虚拟环境的指示。
Visual Studio 2012 有 nuget 版本 2.8.60318.667,与 Reactive.Extensions 3.1.1 不兼容。
如果将 System.Reactive.* 包手动复制到我的解决方案的包目录中,当我从 Visual Studio UI 启动包管理器并浏览已安装的包时:而不是 habing 已安装包的列表,将显示以下错误:
“System.Reactive.Core”已经为“System.Reactive.Interfaces”定义了一个依赖项。错误
如果我使用 de package manager 命令安装包: install-package System.Reactive 会显示以下错误:“System.Reactive 3.1.1”包需要 NuGet 客户端版本“2.8.1”或更高版本,但当前的 NuGet 版本是'2.8.60318.667'。
c# ×3
angular ×2
azure ×1
comparator ×1
deployment ×1
javascript ×1
json.net ×1
kudu ×1
moq ×1
promise ×1
python ×1
signalr ×1
soap ×1
typescript ×1
unit-testing ×1
wcf ×1