小编Ale*_*lex的帖子

通过VBScript调用WCF服务

有一个配置的WCF服务:

<services>
  <service name="MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint 
      binding="basicHttpBinding"  
      contract="IMyService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8001/MyService" />
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

这个脚本应该调用它:

Option Explicit

Dim soapClient
Dim serviceUri
Dim serviceName
Dim portName
Dim result

serviceUri = "http://localhost:8001/MyService"
serviceName = "MyService"
portName = "BasicHttpBinding_IMyService"

Set soapClient = CreateObject("MSSOAP.soapClient")
soapClient.ClientProperty("ServerHTTPRequest") = True
soapClient.mssoapinit serviceUri & "?WSDL", serviceName, portName
Run Code Online (Sandbox Code Playgroud)

运行脚本时出现此错误:

客户端:WSDLReader:分析WSDL文件失败HRESULT = 0x8 0004005 - WSDLReader:服务初始化失败HRESULT = 0x80004005 - WSDL服务:服务端口初始化服务MyService失败HRESULT = 0x80004005 - WSDLPort:分析端口BasicHttpBinding_IMyService的绑定信息失败HRESULT = 0x80004005 …

vbscript wcf msxml

10
推荐指数
1
解决办法
2万
查看次数

从C#构建Python脚本和调用方法

有没有办法让这个场景有效?

有一个Python脚本.它通过使用IronPython运行此脚本而内置到DLL中:

import clr
clr.CompileModules("CompiledScript.dll", "script.py")
Run Code Online (Sandbox Code Playgroud)

目标是从C#代码调用此DLL的方法..NET Reflector显示DLL中有一个类 - DLRCashedCode我们感兴趣的方法是此类的私有静态方法.

例如,脚本中有一个函数:

def scriptMethod(self, text):
...
Run Code Online (Sandbox Code Playgroud)

它在DLL中的表示是:

private static object scriptMethod(Closure closure1, PythonFunction $function, object self, object text)
{
...
}
Run Code Online (Sandbox Code Playgroud)

Closure并且PythonFunction是IronPython类(来自Microsoft.Scripting.dll和IronPython.dll).

到现在为止还挺好.是否有可能通过C#代码调用此方法?使用反射的想法

Type t = typeof(DLRCachedCode);

string methodName = "scriptMethod";
MethodInfo method = t.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);

object[] parameters = new object[] { "param1", "param2" };  // the "params problem"
method.Invoke(null, parameters);
Run Code Online (Sandbox Code Playgroud)

因为设置方法的参数似乎更难.如果它们(如何)正确初始化,我们是否可以期望该方法能够顺利运行?

有没有更好的方法从C#调用此方法?出于各种不同的原因,我们希望将脚本构建为.NET程序集,而不是调用脚本本身.

c# python ironpython

10
推荐指数
2
解决办法
7538
查看次数

托管代码中的免费非托管内存分配

.NET应用程序调用C dll.C代码为char数组分配内存并返回此数组作为结果..NET应用程序将此结果作为字符串获取.

C代码:

extern "C" __declspec(dllexport) char* __cdecl Run()
{
    char* result = (char*)malloc(100 * sizeof(char));
    // fill the array with data
    return result;
}
Run Code Online (Sandbox Code Playgroud)

C#代码:

[DllImport("Unmanaged.dll")]
private static extern string Run();

...
string result = Run();
// do something useful with the result and than leave it out of scope
Run Code Online (Sandbox Code Playgroud)

对它的一些测试表明垃圾收集器没有释放C代码分配的内存.

任何帮助将不胜感激.:)

.net memory-management unmanaged dllimport

7
推荐指数
3
解决办法
7361
查看次数