我创建了Windows服务,并使用installutil.exe安装了它。
但是,即使HTTPGetEnabled设置为true,我也无法访问'MEX'端点。 总是收到错误“此服务的元数据发布当前被禁用。”
您能帮我解决这个问题吗?
下面是我的App.Config文件
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.BEFORE_RESUME)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeReactApp", null);
setContentView(mReactRootView);
答案 0 :(得分:0)
尽管我们已经设置了httpGetEnabled
属性,但是我们需要设置HTTP基址来启用serviceMetadata
属性。
请参考下面的代码段。
<system.serviceModel>
<services>
<service name="ConsoleApp3.TestService" behaviorConfiguration="mybeh">
<endpoint address="myservice" binding="basicHttpBinding" contract="ConsoleApp3.ITestService" bindingConfiguration=""></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration=""></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:21011/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mybeh">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
请随时让我知道问题是否仍然存在。
已更新。
static void Main(string[] args)
{
Uri uri = new Uri("http://localhost:21011");
BasicHttpBinding binding = new BasicHttpBinding();
using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
{
sh.AddServiceEndpoint(typeof(IService), binding, "");
ServiceMetadataBehavior smb;
smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
smb = new ServiceMetadataBehavior()
{
HttpGetEnabled = true
};
sh.Description.Behaviors.Add(smb);
}
Binding mexbinding = MetadataExchangeBindings.CreateMexHttpBinding();
sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
sh.Opened += delegate
{
Console.WriteLine("Service is ready");
};
sh.Closed += delegate
{
Console.WriteLine("Service is clsoed");
};
sh.Open();
Console.ReadLine();
//pause
sh.Close();
Console.ReadLine();
}